UNPKG

return-style

Version:

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

13 lines (11 loc) 308 B
import { Awaitable } from '@blackglory/prelude' export async function getSuccessAsync<T>( fn: () => Awaitable<T> ): Promise<[succeeded: true, result: T] | [succeeded: false, result: undefined]> { try { const result = await fn() return [true, result] } catch { return [false, void 0] } }