Locking
public protocol Locking
A type that mutually excludes execution of code such that only one unit of code is running at any given time. An implementing type may choose to have readers-writer semantics, such that many readers can read at once, or lock around all reads and writes the same way.
-
Call
bodywith a reading lock.If the implementing type models a readers-writer lock, this function may behave differently to
withWriteLock(_:).Declaration
Swift
func withReadLock<Return>(_ body: () throws -> Return) rethrows -> ReturnParameters
bodyA function that reads a value while locked.
Return Value
The value returned from the given function.
-
withAttemptedReadLock(_:)Default implementationAttempt to call
bodywith a reading lock.If the lock cannot immediately be taken, return
nilinstead of executingbody.See
withReadLock(_:)Default Implementation
Declaration
Swift
func withAttemptedReadLock<Return>(_ body: () throws -> Return) rethrows -> Return?Return Value
The value returned from the given function, or
nil. -
withWriteLock(_:)Default implementationCall
bodywith a writing lock.If the implementing type models a readers-writer lock, this function may behave differently to
withReadLock(_:).Default Implementation
Declaration
Swift
func withWriteLock<Return>(_ body: () throws -> Return) rethrows -> ReturnParameters
bodyA function that writes a value while locked, then returns some value.
Return Value
The value returned from the given function.
View on GitHub
Install in Dash
Locking Protocol Reference