@nebius/js-sdk - v0.2.54
    Preparing search index...

    Coordinates cancellation for several waits and promises.

    One instance is a one-way lifecycle. After cancel runs, Cancelable.isCanceled stays true; create a new instance for later work. Cancellation rejects registered operations with CancelError. It does not stop the underlying work of a promise passed to guard.

    import {
    Cancelable,
    CancelError,
    } from '@nebius/js-sdk/runtime/util/cancelable';

    const cancellation = new Cancelable();
    const work = cancellation.guard(new Promise<string>(() => {}));
    cancellation.cancel();

    try {
    await work;
    } catch (error) {
    if (error instanceof CancelError) {
    // The caller requested cancellation.
    }
    }
    Index
    • Coordinates cancellation for several waits and promises.

      One instance is a one-way lifecycle. After cancel runs, Cancelable.isCanceled stays true; create a new instance for later work. Cancellation rejects registered operations with CancelError. It does not stop the underlying work of a promise passed to guard.

      Returns Cancelable

    • Cancels registered operations and clears their delay timers.

      Calling this method more than once is safe.

      Returns void

    • Rejects the returned promise when this instance is canceled.

      The source promise continues to run because JavaScript promises do not have a general cancellation operation.

      Type Parameters

      • T

      Parameters

      • promise: PromiseLike<T>

      Returns Promise<T>

    • Waits for a duration or rejects with CancelError after cancellation.

      The timer does not keep a Node.js process alive.

      Parameters

      • ms: number

      Returns Promise<void>

    • Applies both this instance's cancellation and a timeout to a promise.

      Neither condition stops the source promise.

      Type Parameters

      • T

      Parameters

      • promise: PromiseLike<T>
      • ms: number

      Returns Promise<T>