Atomic

public final class Atomic<Value>

An atomic variable.

  • Atomically get or set the value of the variable.

    Declaration

    Swift

    public var value: Value { get set }
  • Initialize the variable with the given initial value.

    Declaration

    Swift

    public init(_ value: Value)

    Parameters

    value

    Initial value for self.

  • Atomically modifies the variable.

    Declaration

    Swift

    @discardableResult
    public func modify<Result>(_ action: (inout Value) throws -> Result) rethrows -> Result

    Parameters

    action

    A closure that takes the current value.

    Return Value

    The result of the action.

  • Atomically perform an arbitrary action using the current value of the variable.

    Declaration

    Swift

    @discardableResult
    public func withValue<Result>(_ action: (Value) throws -> Result) rethrows -> Result

    Parameters

    action

    A closure that takes the current value.

    Return Value

    The result of the action.

  • Atomically replace the contents of the variable.

    Declaration

    Swift

    @discardableResult
    public func swap(_ newValue: Value) -> Value

    Parameters

    newValue

    A new value for the variable.

    Return Value

    The old value.