Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 6x 207x 207x 206x | /** * Given a promise awaits it and returns a 3-tuple, with the following members: * * - First entry is either the resolved value of the promise or `undefined`. * - Second entry is either the error thrown by promise or `undefined`. * - Third entry is a boolean, truthy if promise was resolved and falsy if rejected. * * @param promise Promise to convert to 3-tuple. */ export const of = async <T, E = unknown>(promise: Promise<T>): Promise<[T | undefined, E | undefined, boolean]> => { try { return [await promise, undefined, true]; } catch (error: unknown) { return [undefined, error as E, false]; } }; |