@kayahr/scope
    Preparing search index...

    Class ScopeAbstract

    Public scope for lifetime, disposal, and scope-local values.

    A scope owns disposal callbacks registered while run executes synchronously and stores local values through scope slots.

    Implements

    • AsyncDisposable
    • Disposable
    Index
    • Creates a new scope optionally owned by an explicit parent scope.

      Parameters

      • parent: Scope | null

        The explicit parent scope, or null when there is none.

      Returns Scope

      ScopeError - When parent was already disposed.

    • Asynchronously disposes this scope and all resources currently owned by it.

      Returns Promise<void>

    • Disposes this scope and all resources currently owned by it.

      Returns void

    • Clears the currently owned child scopes, cleanup callbacks, and slot values.

      Returns void

    • Asynchronously clears the currently owned child scopes, cleanup callbacks, and slot values.

      Returns Promise<void>

    • Deletes the value stored directly on this scope for the given slot.

      Parameters

      • slot: ScopeSlot<unknown>

        The slot to delete locally.

      Returns boolean

      True when a local value was removed.

      ScopeError - When the scope was already disposed.

    • Disposes this scope and all resources currently owned by it.

      Child scopes are disposed in reverse creation order before cleanup callbacks run in reverse registration order.

      Returns void

      ScopeError - When the scope owns asynchronous cleanup and must be disposed through disposeAsync.

    • Asynchronously disposes this scope and all resources currently owned by it.

      Child scopes are disposed sequentially in reverse creation order before synchronous and asynchronous cleanup callbacks run sequentially in reverse registration order. Concurrent calls share the same disposal operation.

      Returns Promise<void>

      Promise which resolves when disposal has completed.

    • Returns the nearest value stored for the given slot on this scope or one of its parents.

      Type Parameters

      • T

      Parameters

      Returns T | undefined

      The nearest stored value, or undefined when no value exists in this scope chain.

      ScopeError - When the scope was already disposed.

    • Returns the value stored directly on this scope for the given slot.

      Type Parameters

      • T

      Parameters

      Returns T | undefined

      The locally stored value, or undefined when no local value exists.

      ScopeError - When the scope was already disposed.

    • Returns the current parent scope, or null when this scope currently has no parent.

      Returns Scope | null

      The current parent scope, or null when there is none.

      ScopeError - When the scope was already disposed.

    • Returns whether this scope stores a local value for the given slot.

      Parameters

      Returns boolean

      True when this scope has a local value for the slot.

      ScopeError - When the scope was already disposed.

    • Returns whether disposal of this scope has started.

      Returns boolean

      True when this scope is being disposed or was already disposed.

    • Registers an asynchronous cleanup callback to run when this scope is disposed asynchronously.

      A scope owning asynchronous cleanup must be disposed through disposeAsync. When the scope is already disposed, the cleanup runs immediately and the returned promise represents its completion.

      Parameters

      • cleanup: () => PromiseLike<void>

        The asynchronous cleanup callback to register.

      Returns Promise<void>

      Promise which resolves immediately after registration, or after immediate cleanup of an already disposed scope.

    • Registers a cleanup callback to run when this scope is disposed.

      Parameters

      • cleanup: () => void

        The cleanup callback to register.

      Returns void

    • Returns whether this scope or any owned child scope requires asynchronous disposal.

      Returns boolean

      True when asynchronous disposal is required.

    • Runs the given callback with this scope active.

      Only the synchronous execution of the callback belongs to this scope. Work created after an await no longer belongs to this scope. If the callback returns a promise, that promise is returned as-is and is not awaited.

      Type Parameters

      • T

      Parameters

      • func: () => T

        The callback to run inside this scope.

      Returns T

      The value returned by the callback.

      ScopeError - When the scope was already disposed.

    • Stores one scope-local value on this scope.

      Type Parameters

      • T

      Parameters

      • slot: ScopeSlot<T>

        The slot identifying the stored value.

      • value: T

        The value to store.

      Returns T

      The stored value.

      ScopeError - When the scope was already disposed.