1 | "use strict";
|
2 | exports.__esModule = true;
|
3 | exports.iterateLater = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var _1 = require(".");
|
6 | function iterateLater() {
|
7 | var nextInLine = (0, _1.resolveLater)();
|
8 | var queue = [nextInLine];
|
9 | var completed = {};
|
10 | var next = function (value) {
|
11 | var _a = tslib_1.__read(nextInLine, 2), _ = _a[0], resolve = _a[1];
|
12 | resolve(value);
|
13 | nextInLine = (0, _1.resolveLater)();
|
14 | queue.unshift(nextInLine);
|
15 | };
|
16 | var iterate = function () {
|
17 | var _a, _b;
|
18 | return tslib_1.__asyncGenerator(this, arguments, function () {
|
19 | var _c, nextValue;
|
20 | return tslib_1.__generator(this, function (_d) {
|
21 | switch (_d.label) {
|
22 | case 0:
|
23 | if (!(queue.length > 0)) return [3 , 5];
|
24 | _c = tslib_1.__read(queue.pop(), 1), nextValue = _c[0];
|
25 | return [4 , tslib_1.__await(nextValue)];
|
26 | case 1:
|
27 | if (!((_d.sent()) !== completed)) return [3 , 4];
|
28 | return [4 , tslib_1.__await(nextValue)];
|
29 | case 2: return [4 , _d.sent()];
|
30 | case 3:
|
31 | _d.sent();
|
32 | _d.label = 4;
|
33 | case 4:
|
34 | if ((_b = (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.VERBOSE)
|
35 | console.debug("In queue: ".concat(queue.length));
|
36 | return [3 , 0];
|
37 | case 5: return [2 ];
|
38 | }
|
39 | });
|
40 | });
|
41 | };
|
42 | var complete = function () {
|
43 | var _a = tslib_1.__read(nextInLine, 2), _ = _a[0], resolve = _a[1];
|
44 | resolve(completed);
|
45 | };
|
46 | return [iterate(), next, complete];
|
47 | }
|
48 | exports.iterateLater = iterateLater;
|