SynchronizedVar
public class SynchronizedVar<T>
Thread-Safe variable wrapper.
Makes sure the get and set are happening synchronously by using a Mutex for reader/writing to the wrapped value
-
Canonical constructor
Declaration
Swift
public init(_ value: T)
-
Get/Set the value for this SynchronizedVar in a thread-safe (blocking) manner
Declaration
Swift
public var value: T { get }
-
Set a new value in a transaction to make sure there is no potential ‘gap’ between get and consecutive set
Declaration
Swift
public func set(transaction block: @escaping (T) -> T)
Parameters
block
the transaction that gets the oldValue and must return the newValue that will be stored in the backing value.