AtomicVariable

final class AtomicVariable<A>

Atomic (synchronized) variable access - warning: The class shares one queue for synchronizing in every instance, so don’t access an atomic variable from another’s atomically sync closure.

  • Undocumented

    Declaration

    Swift

    final class AtomicVariable<A>
  • Get the current value of the variable.

    Declaration

    Swift

    var value: A
  • Create an AtomicVariable - parameter value: the initial value.

    Declaration

    Swift

    init(_ value: A)

    Parameters

    value

    the initial value.

  • Get an atomic (synchronized) closure with the variable as a parameter - parameter sync: the closure with the variable as a parameter. - example: increase an int variable by one

    x.atomically { value in value += 1 }

    Declaration

    Swift

    func atomically<T>(_ sync: @escaping (inout A) -> (T)) -> T

    Parameters

    sync

    the closure with the variable as a parameter.