Protected
public final class Protected<T>
A protected value only allows access from within a locking statement. This prevents accidental unsafe access when thread safety is desired.
-
Creates a protected
value
with a type implementing alock
.Declaration
Swift
public init(initialValue value: T, lock: Locking = NativeLock())
-
Give read access to the item within
body
.Declaration
Swift
@inlinable public func withReadLock<Return>(_ body: (T) throws -> Return) rethrows -> Return
Parameters
body
A function that reads from the contained item.
Return Value
The value returned from the given function.
-
Give write access to the item within the given function.
Declaration
Swift
@inlinable public func withWriteLock<Return>(_ body: (inout T) throws -> Return) rethrows -> Return
Parameters
body
A function that writes to the contained item, and returns some value.
Return Value
The value returned from the given function.
-
Declaration
Swift
public var debugDescription: String { get }
-
Declaration
Swift
public var customMirror: Mirror { get }