@studyportals/sp-hs-misc
Version:
Miscellaneous code used in HouseStark's projects
28 lines • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottledRequestSenderDecorator = void 0;
const throttleable_class_1 = require("../utils/throttleable.class");
class ThrottledRequestSenderDecorator {
target;
throttler;
constructor(target, throttler) {
this.target = target;
this.throttler = throttler;
}
async sendAndExtractBody(request) {
return this.createAndEnqueueTask(() => this.target.sendAndExtractBody(request));
}
async send(request) {
return this.createAndEnqueueTask(() => this.target.send(request));
}
createAndEnqueueTask(actionFn) {
const task = this.createTask(actionFn);
this.throttler.enqueueTask(task);
return task.createObservingPromise();
}
createTask(actionFn) {
return new throttleable_class_1.Throttleable(actionFn);
}
}
exports.ThrottledRequestSenderDecorator = ThrottledRequestSenderDecorator;
//# sourceMappingURL=throttled-request-sender-decorator.class.js.map