UNPKG

surrogate

Version:

Object method hooks made easy

42 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NextAsyncContext = void 0; const executionContext_1 = require("./executionContext"); class NextAsyncContext extends executionContext_1.ExecutionContext { async start() { return new Promise((resolve, reject) => { this.resolver = resolve; this.rejecter = reject; try { this.runNext(this.nextNode); } catch (error) { this.handleError(this.nextNode, error); } }); } complete() { this.resolver(this.returnValue); } async runOriginal(node) { const { container, context } = node; const handler = container.getHandler(context); try { const result = await handler.apply(context.receiver, this.currentArgs); this.setReturnValue(result); this.runNext(node.nextNode); } catch (error) { this.handleError(this.nextNode, error); } } handleError(node, error) { this.logError(node, error); this.rejecter(error); } bail(bailWith) { this.resolver(bailWith !== null && bailWith !== void 0 ? bailWith : this.returnValue); } } exports.NextAsyncContext = NextAsyncContext; //# sourceMappingURL=nextAsyncContext.js.map