UNPKG

serverless-offline-edge-lambda

Version:

A plugin for the Serverless Framework that simulates the behavior of AWS CloudFront Edge Lambdas while developing offline.

39 lines 1.24 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.CallbackPromise = void 0; const deferred_promise_1 = require("./deferred-promise"); /** * The `CallbackPromise` provides a mechanism for creating a promise that can be resolved or rejected * like a Node callback function. */ class CallbackPromise { constructor(strict = true) { this.promise = new deferred_promise_1.DeferredPromise(); this.hasBeenCalled = false; this[_a] = 'Promise'; this.callback = (err, result) => { if (strict && this.hasBeenCalled) { throw new Error('Callback has already been invoked'); } this.hasBeenCalled = true; if (err) { this.promise.reject(err); return; } this.promise.resolve(result); }; } then(onfulfilled, onrejected) { return this.promise.then(onfulfilled); } catch(onrejected) { return this.promise.catch(onrejected); } finally(onfinally) { return this.promise.finally(onfinally); } } exports.CallbackPromise = CallbackPromise; _a = Symbol.toStringTag; //# sourceMappingURL=callback-promise.js.map