HAProtected

public class HAProtected<ValueType>

Wrapper around a value with a lock

Provided publicly as a convenience in case the library uses it anywhere.

  • Create a new protected value

    Declaration

    Swift

    public init(value: ValueType)

    Parameters

    value

    The initial value

  • Get and optionally change the value

    Declaration

    Swift

    @discardableResult
    public func mutate<HandlerType>(using handler: (inout ValueType) -> HandlerType) -> HandlerType

    Parameters

    handler

    Will be invoked immediately with the current value as an inout parameter.

    Return Value

    The value returned by the handler block

  • Read the value and get a result out of it

    Declaration

    Swift

    public func read<T>(_ handler: (ValueType) -> T) -> T

    Parameters

    handler

    Will be invoked immediately with the current value.

    Return Value

    The value returned by the handler block