Evercatch - v0.3.1
    Preparing search index...

    Function fromAsyncThrowable

    • Wraps an async function that may throw into a function that returns a ResultAsync.

      Type Parameters

      • A extends any[]
      • T
      • E extends string

      Parameters

      • fn: (...args: A) => Promise<T>

        The async function to wrap that may throw an error

      • label: E

        A label to identify the error when the function throws

      Returns ResultAsyncFn<A, T, E>

      A function that returns a ResultAsync

      const safeFetch = fromAsyncThrowable(fetch, 'FETCH_ERROR');
      const success = await safeFetch('https://api.example.com/data'); // [null, data]
      const fail = await safeFetch('invalid-url'); // [Err<'FETCH_ERROR'>, undefined]