t-tasks
    Preparing search index...

    Function fromAbortSignal

    • Lift an async operation that accepts an AbortSignal into a Task.

      Creates an internal AbortController and passes its signal to producer. If the resulting task is canceled or rejected externally, controller.abort() is called automatically.

      Type Parameters

      • R

        returned task resolve type

      Parameters

      • producer: (signal: AbortSignal) => PromiseLike<R>

        factory function receiving an AbortSignal

      Returns Task<R>

      task wrapping the operation

      const fetchUser = (id: string) =>
      Task.fromAbortSignal((signal) =>
      fetch(`/api/users/${id}`, { signal }).then((res) => res.json())
      );