UNPKG

return-style

Version:

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

11 lines (10 loc) 264 B
export async function getFailurePromise<E = Error>( promise: PromiseLike<unknown> ): Promise<[failed: true, error: E] | [failed: false, error: undefined]> { try { await promise return [false, void 0] } catch (err) { return [true, err as E] } }