@vgerbot/async
    Preparing search index...

    Function cancellable

    Core implementation of the cancellable task creator.

    The type of the task result

    The async function to execute, receives a CancellableToken

    Full configuration options including retry logic and fallback behavior

    A CancellableHandle that resolves to T

    • Creates a cancellable asynchronous task. Returns a CancellableHandle that can be used to cancel the task or await its result.

      Type Parameters

      • T

        The type of the task result

      Parameters

      • asyncTask: AsyncTask<T>

        The async function to execute, receives a CancellableToken

      Returns CancellableHandle<T>

      A CancellableHandle for managing the task

      const handle = cancellable(async (token) => {
      await token.sleep(1000);
      await token.wrap(fetch('/api/xxx', { signal: token.signal }))
      await token.wrap(cancellable(async token => {
      await token.wrap(new Promise(resolve => {
      setTimeout(resolve, 1000);
      }))
      }))
      return "done";
      });

      // Cancel the task
      handle.cancel("User cancelled");
    • Creates a cancellable asynchronous task with options. Errors will be rejected unless fallback is provided.

      Type Parameters

      • T

        The type of the task result

      Parameters

      • asyncTask: (token: CancellableToken) => Promise<T>

        The async function to execute, receives a CancellableToken

      • Optionaloptions: CancellableOptions<T>

        Configuration options including retry, timeout and fallback

      Returns CancellableHandle<T>

      A CancellableHandle for managing the task