Spaces:
Paused
Paused
File size: 1,408 Bytes
9ada4bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/RequestController.ts
var _outvariant = require('outvariant');
var _deferredpromise = require('@open-draft/deferred-promise');
var RequestController = class {
constructor(request) {
this.request = request;
this.responsePromise = new (0, _deferredpromise.DeferredPromise)();
}
respondWith(response) {
_outvariant.invariant.call(void 0,
this.responsePromise.state === "pending",
'Failed to respond to "%s %s" request: the "request" event has already been responded to.',
this.request.method,
this.request.url
);
this.responsePromise.resolve(response);
}
};
// src/utils/toInteractiveRequest.ts
function toInteractiveRequest(request) {
const requestController = new RequestController(request);
Reflect.set(
request,
"respondWith",
requestController.respondWith.bind(requestController)
);
return {
interactiveRequest: request,
requestController
};
}
// src/utils/emitAsync.ts
async function emitAsync(emitter, eventName, ...data) {
const listners = emitter.listeners(eventName);
if (listners.length === 0) {
return;
}
for (const listener of listners) {
await listener.apply(emitter, data);
}
}
exports.toInteractiveRequest = toInteractiveRequest; exports.emitAsync = emitAsync;
//# sourceMappingURL=chunk-MQJ3JOOK.js.map |