als-unhooked
    Preparing search index...

    Class ALS<K, V>

    The backbone of the Modern API, this class provides a modern implementation for managing key-value stores within asynchronous contexts. It leverages AsyncLocalStorage to create, retrieve, and manipulate context-specific data.

    Type Parameters

    • K = any

      The type of keys in the store.

    • V = any

      The type of values in the store.

    Hierarchy (View Summary)

    Index

    Constructors

    Instance Methods

    Properties

    Constructors

    Instance Methods

    • Runs a function within a new store context.

      Type Parameters

      • T

      Parameters

      • fn: () => T

        The function to run.

      • Optionaldefaults: Dictionary<K, V>

        The default values to initialize the store with.

      Returns T

      The result of the function.

    • Experimental

      Exits the current store context and runs a function. Marked experimental as it depends on AsyncLocalStorage#exit

      Type Parameters

      • T

      Parameters

      • fn: () => T

        The function to run.

      Returns T

      The result of the function.

    • Experimental

      Binds a function to the current store context. Marked experimental as it depends on AsyncLocalStorage.bind

      Type Parameters

      • T extends () => any

      Parameters

      • fn: T

        The function to bind.

      Returns T

      The bound function.

    • Retrieves a value from the store by key.

      Type Parameters

      • T = V

      Parameters

      • key: K

        The key to retrieve the value for.

      Returns undefined | T

      The value associated with the key, or undefined if the key does not exist.

    • Sets a value in the store by key.

      Type Parameters

      • T = V

      Parameters

      • key: K

        The key to set the value for.

      • value: T

        The value to set.

      Returns void

    Properties

    d: Object = ...
    asyncLocalStorage: AsyncLocalStorage<Map<K, V>>