package.dist.src.internal.middleware.in-flight-request-count-middleware.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Client SDK for Momento services
The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InFlightRequestCountMiddleware = void 0;
class InFlightRequestCountMiddlewareRequestHandler {
constructor(logger) {
this.logger = logger;
this.inFlightRequestsAtStart =
++InFlightRequestCountMiddleware.numActiveRequests;
}
onRequestBody(request) {
return Promise.resolve(request);
}
onRequestMetadata(metadata) {
return Promise.resolve(metadata);
}
onResponseBody(response) {
this.receivedResponseBody = true;
if (this.done())
this.logStatusInformation();
return Promise.resolve(response);
}
onResponseMetadata(metadata) {
return Promise.resolve(metadata);
}
onResponseStatus(status) {
this.receivedResponseStatus = true;
if (this.done())
this.logStatusInformation();
return Promise.resolve(status);
}
done() {
return this.receivedResponseBody && this.receivedResponseStatus;
}
logStatusInformation() {
const inFlightRequestsAtEnd = --InFlightRequestCountMiddleware.numActiveRequests;
this.logger.debug(`Request completed; in-flight requests at start: ${this.inFlightRequestsAtStart}, in-flight requests at completion: ${inFlightRequestsAtEnd}`);
}
}
class InFlightRequestCountMiddleware {
constructor(loggerFactory) {
this.logger = loggerFactory.getLogger(this);
}
onNewRequest() {
return new InFlightRequestCountMiddlewareRequestHandler(this.logger);
}
}
exports.InFlightRequestCountMiddleware = InFlightRequestCountMiddleware;
InFlightRequestCountMiddleware.numActiveRequests = 0;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW4tZmxpZ2h0LXJlcXVlc3QtY291bnQtbWlkZGxld2FyZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9pbnRlcm5hbC9taWRkbGV3YXJlL2luLWZsaWdodC1yZXF1ZXN0LWNvdW50LW1pZGRsZXdhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6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