FastWriteLock
public protocol FastWriteLock
A generic interface describing a lock that can be acquired for synchronous (blocking) reading or potentially asynchronous writing.
Because the write operations of a FastWriteLock
may be (but are not
guaranteed to be) performed asynchronously, unlike with the completely
synchronous Lock
protocol:
- Write operations require an
@escaping
closure - A value cannot be returned from a write operation
The underlying FastWriteLock
implementation determines whether and when
write operations are performed asynchronously.
-
Describes the underlying locking mechanism used by the receiver.
Declaration
Swift
var mechanism: LockMechanism
-
Executes the given function with a read lock held, returning its result.
The implementation acquires a read lock, executes
fn
and records its result, releases the lock, and returns the result of executingfn
.Declaration
Swift
func read<T>(_ fn: () -> T)
Parameters
fn
A function to perform while a read lock is held.
Return Value
The result of calling
fn()
. -
Executes the given function with the write lock held.
The implementation acquires the write lock, executes
fn
, and then releases the lock it acquired.Declaration
Swift
func write(_ fn: @escaping () -> Void)
Parameters
fn
A function to perform while the write lock is held.