UNPKG

telefunc

Version:

Remote functions. Instead of API.

24 lines (23 loc) 943 B
export { Abort }; export { isAbort }; import { assert, assertUsage, objectAssign } from '../utils.js'; const stamp = '__telefunc_isAbort'; function isAbort(thing) { assert(thing !== Abort); // Caught earlier in `executeTelefunction()` return typeof thing === 'object' && thing !== null && stamp in thing; } function Abort(abortValue) { { // @ts-ignore const that = this; assertUsage(!(typeof that === 'object' && (that === null || that === void 0 ? void 0 : that.constructor) === Abort), 'Do not use the `new` operator: use `throw Abort()` instead of `throw new Abort()`.'); } assertUsage(arguments.length <= 1, 'Abort() accepts only a single argument: use `throw Abort([arg1, arg2])` instead of `throw Abort(arg1, arg2).`'); const abortError = new Error('Abort'); objectAssign(abortError, { isAbort: true, abortValue, [stamp]: true, }); return abortError; }