Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

Hierarchy

Index

Constructors

  • new default<CTX>(ctx?: CTX): default<CTX>

Properties

cache: Dictionary<GlobalCache> = ...

Cache for async operations

context: CTX
deprecated
see

[[Async.ctx]]

ctx: CTX

Context of applying for async handlers

idsMap: WeakMap<object, object> = ...

Map for task identifiers

locked: boolean = false

The lock status. If true, then all new tasks won't be registered.

usedNamespaces: Set<string> = ...

Set of used async namespaces

workerCache: WeakMap<object, boolean> = ...

Cache for initialized workers

linkNames: { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" } = namespaces
deprecated
see

Async.namespaces

Type declaration

  • eventListener: "eventListener"
  • eventListenerPromise: "eventListenerPromise"
  • idleCallback: "idleCallback"
  • idleCallbackPromise: "idleCallbackPromise"
  • immediate: "immediate"
  • immediatePromise: "immediatePromise"
  • interval: "interval"
  • intervalPromise: "intervalPromise"
  • iterable: "iterable"
  • promise: "promise"
  • proxy: "proxy"
  • proxyPromise: "proxyPromise"
  • request: "request"
  • timeout: "timeout"
  • timeoutPromise: "timeoutPromise"
  • worker: "worker"
namespaces: { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" } = namespaces

Map of namespaces for async operations

Type declaration

  • eventListener: "eventListener"
  • eventListenerPromise: "eventListenerPromise"
  • idleCallback: "idleCallback"
  • idleCallbackPromise: "idleCallbackPromise"
  • immediate: "immediate"
  • immediatePromise: "immediatePromise"
  • interval: "interval"
  • intervalPromise: "intervalPromise"
  • iterable: "iterable"
  • promise: "promise"
  • proxy: "proxy"
  • proxyPromise: "proxyPromise"
  • request: "request"
  • timeout: "timeout"
  • timeoutPromise: "timeoutPromise"
  • worker: "worker"

Accessors

  • get linkNames(): { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" }
  • deprecated
    see

    [[Async.namespaces]]

    Returns { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" }

    • eventListener: "eventListener"
    • eventListenerPromise: "eventListenerPromise"
    • idleCallback: "idleCallback"
    • idleCallbackPromise: "idleCallbackPromise"
    • immediate: "immediate"
    • immediatePromise: "immediatePromise"
    • interval: "interval"
    • intervalPromise: "intervalPromise"
    • iterable: "iterable"
    • promise: "promise"
    • proxy: "proxy"
    • proxyPromise: "proxyPromise"
    • request: "request"
    • timeout: "timeout"
    • timeoutPromise: "timeoutPromise"
    • worker: "worker"
  • get namespaces(): { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" }
  • Link to Async.namespaces

    Returns { eventListener: "eventListener"; eventListenerPromise: "eventListenerPromise"; idleCallback: "idleCallback"; idleCallbackPromise: "idleCallbackPromise"; immediate: "immediate"; immediatePromise: "immediatePromise"; interval: "interval"; intervalPromise: "intervalPromise"; iterable: "iterable"; promise: "promise"; proxy: "proxy"; proxyPromise: "proxyPromise"; request: "request"; timeout: "timeout"; timeoutPromise: "timeoutPromise"; worker: "worker" }

    • eventListener: "eventListener"
    • eventListenerPromise: "eventListenerPromise"
    • idleCallback: "idleCallback"
    • idleCallbackPromise: "idleCallbackPromise"
    • immediate: "immediate"
    • immediatePromise: "immediatePromise"
    • interval: "interval"
    • intervalPromise: "intervalPromise"
    • iterable: "iterable"
    • promise: "promise"
    • proxy: "proxy"
    • proxyPromise: "proxyPromise"
    • request: "request"
    • timeout: "timeout"
    • timeoutPromise: "timeoutPromise"
    • worker: "worker"

Methods

  • Cancels the specified iterable object. Notice that cancellation affects only objects that have already been activated by invoking the next method. So, for example, canceled iterable will throw an error on the next invoking of next.

    alias

    Parameters

    • Optional id: AsyncIterable<unknown>

    Returns default<CTX>

  • Cancels the specified iterable or a group of iterable. Notice that cancellation affects only objects that have already been activated by invoking the next method. So, for example, canceled iterable will throw an error on the next invoking of next.

    alias

    Parameters

    • opts: ClearOptionsId<AsyncIterable<unknown>>

      options for the operation

    Returns default<CTX>

  • cancelTask(task: any, name?: string): default<CTX>
  • clearAsync(opts: any, name?: string): default<CTX>
  • Cancels the specified iterable object. Notice that cancellation affects only objects that have already been activated by invoking the next method. So, for example, canceled iterable will throw an error on the next invoking of next.

    Parameters

    • Optional id: Promise<unknown>

    Returns default<CTX>

  • Cancels the specified iterable object. Notice that cancellation affects only objects that have already been activated by invoking the next method. So, for example, canceled iterable will throw an error on the next invoking of next.

    Parameters

    Returns default<CTX>

  • getBaseIterator<T>(iterable: Iterable<T> | AsyncIterable<T>): CanUndef<IterableIterator<T> | AsyncIterableIterator<T>>
  • Returns an iterator from the passed iterable object. Notice, an asynchronous iterator has more priority.

    Type parameters

    • T

    Parameters

    • iterable: Iterable<T> | AsyncIterable<T>

    Returns CanUndef<IterableIterator<T> | AsyncIterableIterator<T>>

  • initCache(name: string, promise?: boolean): GlobalCache
  • iterable<T>(iterable: Iterable<T> | AsyncIterable<T>, opts?: AsyncOptions): AsyncIterable<T> | (AsyncIterable<T> & Iterable<T>)
  • Creates a new asynchronous iterable object from the specified iterable and returns it. If the passed iterable doesn't have Symbol.asyncIterator, it will be created from a synchronous object iterator (the synchronous iterator will also be preserved).

    Notice, until the created promise object isn't executed by invoking the next method, any async operations won't be registered.

    example
    const async = new Async();

    for await (const el of async.iterable([1, 2, 3, 4])) {
    console.log(el);
    }

    Type parameters

    • T

    Parameters

    • iterable: Iterable<T> | AsyncIterable<T>
    • Optional opts: AsyncOptions

    Returns AsyncIterable<T> | (AsyncIterable<T> & Iterable<T>)

  • markAsync(label: string, opts: any, name?: string): default<CTX>
  • markPromise(label: string, id?: Promise<unknown>): default<CTX>
  • markPromise(label: string, opts: ClearOptionsId<Promise<unknown>>): default<CTX>
  • markTask(label: string, task: any, name?: string): default<CTX>
  • Mutes the specified iterable object. Elements that are consumed during the object is muted will be ignored. Notice that muting affects only objects that have already been activated by invoking the next method.

    Parameters

    • Optional id: AsyncIterable<unknown>

    Returns default<CTX>

  • Mutes the specified iterable object or a group of iterable objects. Elements, that are consumed during the object is muted will be ignored. Notice that muting affects only objects that have already been activated by invoking the next method.

    Parameters

    • opts: ClearOptionsId<AsyncIterable<unknown>>

      options for the operation

    Returns default<CTX>

  • onPromiseClear(resolve: Function, reject: Function): Function
  • onPromiseMerge(resolve: Function, reject: Function): Function
  • Creates a new promise that wraps the passed promise and returns it.

    This method doesn't attach any hook or listeners to the object, but if we cancel the operation by using one of Async's methods, like, "cancelPromise", the promise will be rejected.

    The promise can be provided as it is or as a function, that returns a promise.

    example
    const
    async = new Async();

    async.promise(new Promise(() => {
    // ...
    }))

    Type parameters

    • T = unknown

    Parameters

    Returns Promise<T>

  • Creates a new function that wraps the original and returns it.

    This method doesn't attach any hook or listeners to the object, but if we cancel the operation by using one of Async's methods, like, cancelProxy, the target function won't be invoked.

    example
    const
    async = new Async();

    myImage.onload = async.proxy(() => {
    // ...
    });

    Type parameters

    Parameters

    Returns F

  • request<T>(request: (() => PromiseLike<T>) | PromiseLike<T>, opts?: AsyncRequestOptions): Promise<T>
  • Creates a promise that wraps the passed request and returns it.

    This method doesn't attach any hook or listeners to the object, but if we cancel the operation by using one of Async's methods, like, "cancelRequest", the promise will be rejected.

    The request can be provided as a promise or function, that returns a promise. Notice, the method uses Async.promise, but with a different namespace: request instead of promise.

    example
    const async = new Async();
    async.request(fetch('foo/bla'));

    Type parameters

    • T = unknown

    Parameters

    Returns Promise<T>

  • Suspends the specified iterable object. Notice that suspending affects only objects that have already been activated by invoking the next method.

    Parameters

    • Optional id: AsyncIterable<unknown>

    Returns default<CTX>

  • Suspends the specified iterable or a group of iterable objects. Notice that suspending affects only objects that have already been activated by invoking the next method.

    Parameters

    • opts: ClearOptionsId<AsyncIterable<unknown>>

      options for the operation

    Returns default<CTX>

  • Wraps the specified worker object.

    This method doesn't attach any hook or listeners to the object, but every time the same object is registered, Async will increment the number of links that relate to this object. After, when we try to destroy the worker by using one of Async's methods, like, terminateWorker, it will de-increment values of links. When the number of links is equal to zero, Async will try to call a "real" object destructor by using one of the possible destructor methods from the whitelist or by the specified destructor name, also if the worker is a function, it is interpreted as the destructor.

    example
    const
    async = new Async(),
    el = document.createElement('div');

    $el.appendChild(el);

    // This function will work as the worker destructor
    async.worker(() => el.remove());

    const
    myWorker = new Worker('my-worker.js');

    async.worker(myWorker);

    async.clearAll();

    Type parameters

    Parameters

    Returns T