@vgerbot/async
    Preparing search index...

    Function timeout

    • Wraps an async task with a timeout. The task will be automatically cancelled if it doesn't complete within the specified duration.

      Type Parameters

      • T

        The type of the task result

      Parameters

      • task: AsyncTask<T>

        The async task to execute

      • ms: number

        The timeout duration in milliseconds

      • Optionaloptions: CancellableOptions<T>

        Additional cancellable configuration options

      Returns CancellableHandle<T>

      A cancellable handle that resolves to the task result or rejects on timeout

      const handle = timeout(
      async (token) => {
      await token.sleep(2000);
      return "done";
      },
      1000, // 1 second timeout
      );

      await handle; // Throws timeout error after 1 second