UNPKG

return-style

Version:

Non-intrusively convert the result of any function or promise to the user's desired style.

11 lines (10 loc) 294 B
export async function getResultErrorPromise<E = Error, T = unknown>( promise: PromiseLike<T> ): Promise<[result: T, error: undefined] | [result: undefined, error: E]> { try { const result = await promise return [result, void 0] } catch (err) { return [void 0, err as E] } }