DispatchedValue

public class DispatchedValue<T> : DispatchedValueWrapper

Thread-safe value wrapper, using dispatch queues to achieve synchronization.

Note

This class is not KVO-compliant. If you need this, please use subclasses of DispatchedValue.

See also

DispatchedValueWrapper

  • The wrapped value type.

    Declaration

    Swift

    public typealias ValueType = T
  • Initializes a dispatched value object.

    This initializer will use the main queue for synchronization.

    Declaration

    Swift

    public required convenience init(value: T)

    Parameters

    value

    The initial value.

  • Initializes a dispatched value object.

    Declaration

    Swift

    public required init(value: T, queue: DispatchQueue)

    Parameters

    value

    The initial value.

    queue

    The queue to use to achieve synchronization.

  • Atomically gets the wrapped value.

    The getter will be executed on the queue specified in the initialzer.

    Declaration

    Swift

    public func get() -> T

    Return Value

    The actual value.

  • Atomically sets the wrapped value.

    The setter will be executed on the queue specified in the initialzer.

    Declaration

    Swift

    public func set(_ value: T)

    Parameters

    value

    The value to set.

  • Atomically executes a closure on the wrapped value.

    The closure will be passed the actual value of the wrapped value, and is guaranteed to be executed atomically, on the queue specified in the initialzer.

    Declaration

    Swift

    public func execute(closure: (T) -> Void)

    Parameters

    closure

    The close to execute.

  • Atomically executes a closure on the wrapped value, returning some value.

    The closure will be passed the actual value of the wrapped value, and is guaranteed to be executed atomically, on the queue specified in the initialzer.

    Declaration

    Swift

    public func execute<R>(closure: (T) -> R) -> R

    Parameters

    closure

    The close to execute, returning some value.

    Return Value

    The value returned by executing the closure.