TypedThreadLocalStorage

public struct TypedThreadLocalStorage<Underlying> where Underlying : RawThreadLocalStorage

Wrapper around an underlying thread local storage abstraction to provide a nicer, typed thread local storage interface.

  • Key

    Token used to index into the thread local storage.

    See more

    Declaration

    Swift

    public struct Key<Value> where Value : AnyObject
  • Allocates a key for type T.

    Declaration

    Swift

    public static func makeKey<T>(for _: Type<T>) -> Key<T> where T : AnyObject
  • Retrieves the thread-local value for key, if it exists.

    Declaration

    Swift

    public static func get<T>(_ key: Key<T>) -> T? where T : AnyObject
  • Retrieves the thread-local value for key, creating it with defaultValue if it has not previously been set.

    Declaration

    Swift

    public static func get<T: AnyObject>(
      _ key: Key<T>,
      default defaultValue: @autoclosure () -> T
    ) -> T
  • Stores newValue in thread-local storage using key.

    Declaration

    Swift

    public static func set<T>(_ newValue: T?, for key: Key<T>) where T : AnyObject