Function tryIt

A helper to try an async function without forking the control flow. Returns an error first callback like array response as [Error, result]

const [err, user] = await tryit(api.users.find)(userId)
  • Type Parameters

    • Args extends any[]
    • Return

    Parameters

    Returns (
        ...args: Args,
    ) => Return extends Promise<any>
        ? Promise<[Error, undefined] | [undefined, Awaited<Return<Return>>]>
        : [Error, undefined] | [undefined, Return]