UNPKG

@sern/handler

Version:

A complete, customizable, typesafe, & reactive framework for discord bots.

26 lines 823 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wrapAsync = exports.EMPTY_ERR = exports.val = exports.Err = exports.Ok = void 0; const Ok = (value) => ({ ok: true, value }); exports.Ok = Ok; const Err = (error) => ({ ok: false, error }); exports.Err = Err; const val = (r) => r.ok ? r.value : r.error; exports.val = val; exports.EMPTY_ERR = (0, exports.Err)(undefined); /** * Wrap an async operation that may throw an Error (`try-catch` style) into checked exception style * @param op The operation function */ async function wrapAsync(op) { try { return op() .then(exports.Ok) .catch(exports.Err); } catch (e) { return Promise.resolve((0, exports.Err)(e)); } } exports.wrapAsync = wrapAsync; //# sourceMappingURL=result.js.map