UNPKG

return-style

Version:

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

13 lines (11 loc) 287 B
import { Result } from '@classes/result.js' export async function toResultPromise<E = Error, T = unknown>( promise: PromiseLike<T> ): Promise<Result<T, E>> { try { const result = await promise return Result.Ok(result) } catch (err) { return Result.Err(err as E) } }