@coolio/http
Version:
HTTP networking client
36 lines • 1.69 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var ParsedBodyCacheState;
(function (ParsedBodyCacheState) {
ParsedBodyCacheState[ParsedBodyCacheState["UNINITIALIZED"] = 0] = "UNINITIALIZED";
ParsedBodyCacheState[ParsedBodyCacheState["STARTED"] = 1] = "STARTED";
ParsedBodyCacheState[ParsedBodyCacheState["FINISHED"] = 2] = "FINISHED";
})(ParsedBodyCacheState || (ParsedBodyCacheState = {}));
export const cacheParsedBody = (parsedBody) => {
const queue = [];
let body;
let state = 0;
return () => __awaiter(void 0, void 0, void 0, function* () {
switch (state) {
case 0:
state = 1;
body = yield parsedBody();
state = 2;
queue.forEach(q => q());
queue.splice(0, queue.length);
return body;
case 1:
return new Promise(resolve => queue.push(() => resolve(body)));
case 2:
return body;
}
});
};
//# sourceMappingURL=parsedBodyCache.helper.js.map