@shutterstock/p-map-iterable 1.0.11 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -16
- package/dist/src/blocking-queue.js +61 -70
- package/dist/src/blocking-queue.js.map +1 -1
- package/dist/src/blocking-queue.test.js +70 -71
- package/dist/src/blocking-queue.test.js.map +1 -1
- package/dist/src/iterable-mapper.d.ts +173 -30
- package/dist/src/iterable-mapper.d.ts.map +1 -1
- package/dist/src/iterable-mapper.js +255 -141
- package/dist/src/iterable-mapper.js.map +1 -1
- package/dist/src/iterable-mapper.test.js +347 -720
- package/dist/src/iterable-mapper.test.js.map +1 -1
- package/dist/src/iterable-queue-mapper-simple.d.ts +44 -29
- package/dist/src/iterable-queue-mapper-simple.d.ts.map +1 -1
- package/dist/src/iterable-queue-mapper-simple.js +65 -57
- package/dist/src/iterable-queue-mapper-simple.js.map +1 -1
- package/dist/src/iterable-queue-mapper-simple.test.js +34 -35
- package/dist/src/iterable-queue-mapper-simple.test.js.map +1 -1
- package/dist/src/iterable-queue-mapper.d.ts +38 -58
- package/dist/src/iterable-queue-mapper.d.ts.map +1 -1
- package/dist/src/iterable-queue-mapper.js +37 -42
- package/dist/src/iterable-queue-mapper.js.map +1 -1
- package/dist/src/iterable-queue-mapper.test.js +41 -81
- package/dist/src/iterable-queue-mapper.test.js.map +1 -1
- package/dist/src/iterable-queue.js +8 -11
- package/dist/src/iterable-queue.js.map +1 -1
- package/dist/src/iterable-queue.test.js +43 -122
- package/dist/src/iterable-queue.test.js.map +1 -1
- package/package.json +8 -3
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
4
|
/// <reference types="jest" />
|
|
6
5
|
const iterable_mapper_1 = require("./iterable-mapper");
|
|
7
6
|
const util_1 = require("util");
|
|
8
7
|
const sleep = (0, util_1.promisify)(setTimeout);
|
|
9
|
-
function mapper({ value, ms }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return value;
|
|
13
|
-
});
|
|
8
|
+
async function mapper({ value, ms }) {
|
|
9
|
+
await sleep(ms);
|
|
10
|
+
return value;
|
|
14
11
|
}
|
|
15
12
|
class SleepIterator {
|
|
16
13
|
constructor(max) {
|
|
17
14
|
this._current = 1;
|
|
18
15
|
this._max = max;
|
|
19
16
|
}
|
|
20
|
-
[Symbol.asyncIterator]() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
yield yield tslib_1.__await(this._current);
|
|
26
|
-
}
|
|
27
|
-
this._current++;
|
|
17
|
+
async *[Symbol.asyncIterator]() {
|
|
18
|
+
for (let i = 0; i < this._max; i++) {
|
|
19
|
+
await sleep(1 * (i % 10));
|
|
20
|
+
if (this._current <= this._max) {
|
|
21
|
+
yield this._current;
|
|
28
22
|
}
|
|
29
|
-
|
|
23
|
+
this._current++;
|
|
24
|
+
}
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
class ThrowingIterator {
|
|
@@ -41,16 +36,14 @@ class ThrowingIterator {
|
|
|
41
36
|
const delayMS = this._delayMS;
|
|
42
37
|
const throwOnIndex = this._throwOnIndex;
|
|
43
38
|
return {
|
|
44
|
-
next() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return item;
|
|
53
|
-
});
|
|
39
|
+
async next() {
|
|
40
|
+
await sleep(delayMS);
|
|
41
|
+
if (index === throwOnIndex) {
|
|
42
|
+
throw new Error(`throwing on index ${index}`);
|
|
43
|
+
}
|
|
44
|
+
const item = { value: index, done: index === max };
|
|
45
|
+
index++;
|
|
46
|
+
return item;
|
|
54
47
|
},
|
|
55
48
|
};
|
|
56
49
|
}
|
|
@@ -65,8 +58,7 @@ describe('IterableMapper', () => {
|
|
|
65
58
|
jest.clearAllMocks();
|
|
66
59
|
});
|
|
67
60
|
describe('simple tests', () => {
|
|
68
|
-
it('simple mapper works - sync mapper', () =>
|
|
69
|
-
var _a, e_1, _b, _c;
|
|
61
|
+
it('simple mapper works - sync mapper', async () => {
|
|
70
62
|
const max = 100;
|
|
71
63
|
const iterator = new SleepIterator(max);
|
|
72
64
|
let total = 0;
|
|
@@ -78,78 +70,52 @@ describe('IterableMapper', () => {
|
|
|
78
70
|
});
|
|
79
71
|
let lastTotal = 0;
|
|
80
72
|
let loopCount = 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const item = _c;
|
|
86
|
-
loopCount++;
|
|
87
|
-
if (item > lastTotal) {
|
|
88
|
-
lastTotal = item;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
93
|
-
finally {
|
|
94
|
-
try {
|
|
95
|
-
if (!_d && !_a && (_b = prefetcher_1.return)) yield _b.call(prefetcher_1);
|
|
73
|
+
for await (const item of prefetcher) {
|
|
74
|
+
loopCount++;
|
|
75
|
+
if (item > lastTotal) {
|
|
76
|
+
lastTotal = item;
|
|
96
77
|
}
|
|
97
|
-
finally { if (e_1) throw e_1.error; }
|
|
98
78
|
}
|
|
99
79
|
expect(callCount).toBe(max);
|
|
100
80
|
expect(loopCount).toBe(max);
|
|
101
81
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
102
82
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
103
|
-
})
|
|
104
|
-
it('simple mapper works - async mapper', () =>
|
|
105
|
-
var _e, e_2, _f, _g;
|
|
83
|
+
});
|
|
84
|
+
it('simple mapper works - async mapper', async () => {
|
|
106
85
|
const max = 100;
|
|
107
86
|
const iterator = new SleepIterator(max);
|
|
108
87
|
let total = 0;
|
|
109
88
|
let callCount = 0;
|
|
110
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, (value) =>
|
|
89
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, async (value) => {
|
|
111
90
|
callCount++;
|
|
112
91
|
total += value;
|
|
113
|
-
|
|
92
|
+
await sleep(10 * (callCount % 6));
|
|
114
93
|
return total;
|
|
115
|
-
})
|
|
94
|
+
});
|
|
116
95
|
let lastTotal = 0;
|
|
117
96
|
let loopCount = 0;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const item = _g;
|
|
123
|
-
loopCount++;
|
|
124
|
-
if (item > lastTotal) {
|
|
125
|
-
lastTotal = item;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
130
|
-
finally {
|
|
131
|
-
try {
|
|
132
|
-
if (!_h && !_e && (_f = prefetcher_2.return)) yield _f.call(prefetcher_2);
|
|
97
|
+
for await (const item of prefetcher) {
|
|
98
|
+
loopCount++;
|
|
99
|
+
if (item > lastTotal) {
|
|
100
|
+
lastTotal = item;
|
|
133
101
|
}
|
|
134
|
-
finally { if (e_2) throw e_2.error; }
|
|
135
102
|
}
|
|
136
103
|
expect(callCount).toBe(max);
|
|
137
104
|
expect(loopCount).toBe(max);
|
|
138
105
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
139
106
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
140
|
-
})
|
|
141
|
-
it('async mapper works - parallel next() calls', () =>
|
|
142
|
-
var _j, e_3, _k, _l;
|
|
107
|
+
});
|
|
108
|
+
it('async mapper works - parallel next() calls', async () => {
|
|
143
109
|
const max = 100;
|
|
144
110
|
const inputIterator = new SleepIterator(max);
|
|
145
111
|
let total = 0;
|
|
146
112
|
let callCount = 0;
|
|
147
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(inputIterator, (value) =>
|
|
113
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(inputIterator, async (value) => {
|
|
148
114
|
callCount++;
|
|
149
115
|
total += value;
|
|
150
|
-
|
|
116
|
+
await sleep(10 * (callCount % 6));
|
|
151
117
|
return total;
|
|
152
|
-
})
|
|
118
|
+
});
|
|
153
119
|
let lastTotal = 0;
|
|
154
120
|
let loopCount = 0;
|
|
155
121
|
const nextPromises = [];
|
|
@@ -158,35 +124,22 @@ describe('IterableMapper', () => {
|
|
|
158
124
|
nextPromises.push(iterator.next());
|
|
159
125
|
}
|
|
160
126
|
// Wait for all the readers to resolve
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
_m = false;
|
|
166
|
-
const item = _l;
|
|
167
|
-
if (item.done === true) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
loopCount++;
|
|
171
|
-
if (item.value > lastTotal) {
|
|
172
|
-
lastTotal = item.value;
|
|
173
|
-
}
|
|
127
|
+
await Promise.all(nextPromises);
|
|
128
|
+
for await (const item of nextPromises) {
|
|
129
|
+
if (item.done === true) {
|
|
130
|
+
break;
|
|
174
131
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
if (!_m && !_j && (_k = nextPromises_1.return)) yield _k.call(nextPromises_1);
|
|
132
|
+
loopCount++;
|
|
133
|
+
if (item.value > lastTotal) {
|
|
134
|
+
lastTotal = item.value;
|
|
180
135
|
}
|
|
181
|
-
finally { if (e_3) throw e_3.error; }
|
|
182
136
|
}
|
|
183
137
|
expect(callCount).toBe(max);
|
|
184
138
|
expect(loopCount).toBe(max);
|
|
185
139
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
186
140
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
187
|
-
})
|
|
188
|
-
it('right number run in parallel - simple', () =>
|
|
189
|
-
var _o, e_4, _p, _q;
|
|
141
|
+
});
|
|
142
|
+
it('right number run in parallel - simple', async () => {
|
|
190
143
|
const startTime = Date.now();
|
|
191
144
|
const max = 8;
|
|
192
145
|
const delayBetweenMs = 200;
|
|
@@ -203,24 +156,12 @@ describe('IterableMapper', () => {
|
|
|
203
156
|
const prefetcher = new iterable_mapper_1.IterableMapper(input, mapper, { concurrency: 2, maxUnread: 4 });
|
|
204
157
|
let lastSeen = 0;
|
|
205
158
|
let loopCount = 0;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const item = _q;
|
|
211
|
-
loopCount++;
|
|
212
|
-
if (item > lastSeen) {
|
|
213
|
-
lastSeen = item;
|
|
214
|
-
}
|
|
159
|
+
for await (const item of prefetcher) {
|
|
160
|
+
loopCount++;
|
|
161
|
+
if (item > lastSeen) {
|
|
162
|
+
lastSeen = item;
|
|
215
163
|
}
|
|
216
164
|
}
|
|
217
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
218
|
-
finally {
|
|
219
|
-
try {
|
|
220
|
-
if (!_r && !_o && (_p = prefetcher_3.return)) yield _p.call(prefetcher_3);
|
|
221
|
-
}
|
|
222
|
-
finally { if (e_4) throw e_4.error; }
|
|
223
|
-
}
|
|
224
165
|
expect(loopCount).toBe(max);
|
|
225
166
|
expect(lastSeen).toBe(max);
|
|
226
167
|
// Should require at least 2 batches
|
|
@@ -228,7 +169,7 @@ describe('IterableMapper', () => {
|
|
|
228
169
|
expect(Date.now() - startTime).toBeGreaterThan(4 * delayBetweenMs);
|
|
229
170
|
// The runners should never stop because the items are consumed immediately
|
|
230
171
|
expect(startAnotherRunnerSpy).toHaveBeenCalledTimes(0);
|
|
231
|
-
})
|
|
172
|
+
});
|
|
232
173
|
// T0 - Mapping - Start 1, 2, waiting 200 ms
|
|
233
174
|
// Q: []
|
|
234
175
|
// Runners - 2 running
|
|
@@ -277,8 +218,7 @@ describe('IterableMapper', () => {
|
|
|
277
218
|
// Q: []
|
|
278
219
|
// T2300 - Iterate - Finished 7
|
|
279
220
|
// Q: []
|
|
280
|
-
it('right number run in parallel - delay in reading', () =>
|
|
281
|
-
var _s, e_5, _t, _u;
|
|
221
|
+
it('right number run in parallel - delay in reading', async () => {
|
|
282
222
|
const startTime = Date.now();
|
|
283
223
|
const max = 7;
|
|
284
224
|
const mapDelayMs = 200;
|
|
@@ -296,24 +236,12 @@ describe('IterableMapper', () => {
|
|
|
296
236
|
const prefetcher = new iterable_mapper_1.IterableMapper(input, mapper, { concurrency: 2, maxUnread: 4 });
|
|
297
237
|
let lastSeen = 0;
|
|
298
238
|
let loopCount = 0;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const item = _u;
|
|
304
|
-
loopCount++;
|
|
305
|
-
if (item > lastSeen) {
|
|
306
|
-
lastSeen = item;
|
|
307
|
-
}
|
|
308
|
-
yield sleep(readDelayMs);
|
|
239
|
+
for await (const item of prefetcher) {
|
|
240
|
+
loopCount++;
|
|
241
|
+
if (item > lastSeen) {
|
|
242
|
+
lastSeen = item;
|
|
309
243
|
}
|
|
310
|
-
|
|
311
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
312
|
-
finally {
|
|
313
|
-
try {
|
|
314
|
-
if (!_v && !_s && (_t = prefetcher_4.return)) yield _t.call(prefetcher_4);
|
|
315
|
-
}
|
|
316
|
-
finally { if (e_5) throw e_5.error; }
|
|
244
|
+
await sleep(readDelayMs);
|
|
317
245
|
}
|
|
318
246
|
expect(loopCount).toBe(max);
|
|
319
247
|
expect(lastSeen).toBe(max);
|
|
@@ -326,11 +254,10 @@ describe('IterableMapper', () => {
|
|
|
326
254
|
expect(Date.now() - startTime).toBeGreaterThan(mapDelayMs + max * readDelayMs);
|
|
327
255
|
expect(sourceNextSpy).toHaveBeenCalledTimes(max + 1);
|
|
328
256
|
expect(startAnotherRunnerSpy).toHaveBeenCalledTimes(3);
|
|
329
|
-
})
|
|
257
|
+
});
|
|
330
258
|
});
|
|
331
259
|
describe('empty iterables', () => {
|
|
332
|
-
it('empty sync iterable works - sync mapper', () =>
|
|
333
|
-
var _a, e_6, _b, _c;
|
|
260
|
+
it('empty sync iterable works - sync mapper', async () => {
|
|
334
261
|
let total = 0;
|
|
335
262
|
let callCount = 0;
|
|
336
263
|
const prefetcher = new iterable_mapper_1.IterableMapper([], (value) => {
|
|
@@ -340,77 +267,49 @@ describe('IterableMapper', () => {
|
|
|
340
267
|
});
|
|
341
268
|
let lastTotal = 0;
|
|
342
269
|
let loopCount = 0;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const item = _c;
|
|
348
|
-
loopCount++;
|
|
349
|
-
if (item > lastTotal) {
|
|
350
|
-
lastTotal = item;
|
|
351
|
-
}
|
|
270
|
+
for await (const item of prefetcher) {
|
|
271
|
+
loopCount++;
|
|
272
|
+
if (item > lastTotal) {
|
|
273
|
+
lastTotal = item;
|
|
352
274
|
}
|
|
353
275
|
}
|
|
354
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
355
|
-
finally {
|
|
356
|
-
try {
|
|
357
|
-
if (!_d && !_a && (_b = prefetcher_5.return)) yield _b.call(prefetcher_5);
|
|
358
|
-
}
|
|
359
|
-
finally { if (e_6) throw e_6.error; }
|
|
360
|
-
}
|
|
361
276
|
expect(callCount).toBe(0);
|
|
362
277
|
expect(loopCount).toBe(0);
|
|
363
278
|
expect(total).toBe(0);
|
|
364
279
|
expect(lastTotal).toBe(0);
|
|
365
|
-
})
|
|
366
|
-
it('empty sync iterable works - async mapper', () =>
|
|
367
|
-
var _e, e_7, _f, _g;
|
|
280
|
+
});
|
|
281
|
+
it('empty sync iterable works - async mapper', async () => {
|
|
368
282
|
let total = 0;
|
|
369
283
|
let callCount = 0;
|
|
370
|
-
const prefetcher = new iterable_mapper_1.IterableMapper([], (value) =>
|
|
371
|
-
|
|
284
|
+
const prefetcher = new iterable_mapper_1.IterableMapper([], async (value) => {
|
|
285
|
+
await sleep(10);
|
|
372
286
|
callCount++;
|
|
373
287
|
total += value;
|
|
374
288
|
return total;
|
|
375
|
-
})
|
|
289
|
+
});
|
|
376
290
|
let lastTotal = 0;
|
|
377
291
|
let loopCount = 0;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const item = _g;
|
|
383
|
-
loopCount++;
|
|
384
|
-
if (item > lastTotal) {
|
|
385
|
-
lastTotal = item;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
390
|
-
finally {
|
|
391
|
-
try {
|
|
392
|
-
if (!_h && !_e && (_f = prefetcher_6.return)) yield _f.call(prefetcher_6);
|
|
292
|
+
for await (const item of prefetcher) {
|
|
293
|
+
loopCount++;
|
|
294
|
+
if (item > lastTotal) {
|
|
295
|
+
lastTotal = item;
|
|
393
296
|
}
|
|
394
|
-
finally { if (e_7) throw e_7.error; }
|
|
395
297
|
}
|
|
396
298
|
expect(callCount).toBe(0);
|
|
397
299
|
expect(loopCount).toBe(0);
|
|
398
300
|
expect(total).toBe(0);
|
|
399
301
|
expect(lastTotal).toBe(0);
|
|
400
|
-
})
|
|
401
|
-
it('empty async iterable works - sync mapper', () =>
|
|
402
|
-
var _j, e_8, _k, _l;
|
|
302
|
+
});
|
|
303
|
+
it('empty async iterable works - sync mapper', async () => {
|
|
403
304
|
let total = 0;
|
|
404
305
|
let callCount = 0;
|
|
405
306
|
const prefetcher = new iterable_mapper_1.IterableMapper((() => {
|
|
406
307
|
return {
|
|
407
308
|
[Symbol.asyncIterator]() {
|
|
408
309
|
return {
|
|
409
|
-
next() {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return { value: undefined, done: true };
|
|
413
|
-
});
|
|
310
|
+
async next() {
|
|
311
|
+
await sleep(100);
|
|
312
|
+
return { value: undefined, done: true };
|
|
414
313
|
},
|
|
415
314
|
};
|
|
416
315
|
},
|
|
@@ -422,234 +321,183 @@ describe('IterableMapper', () => {
|
|
|
422
321
|
});
|
|
423
322
|
let lastTotal = 0;
|
|
424
323
|
let loopCount = 0;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const item = _l;
|
|
430
|
-
loopCount++;
|
|
431
|
-
if (item > lastTotal) {
|
|
432
|
-
lastTotal = item;
|
|
433
|
-
}
|
|
324
|
+
for await (const item of prefetcher) {
|
|
325
|
+
loopCount++;
|
|
326
|
+
if (item > lastTotal) {
|
|
327
|
+
lastTotal = item;
|
|
434
328
|
}
|
|
435
329
|
}
|
|
436
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
437
|
-
finally {
|
|
438
|
-
try {
|
|
439
|
-
if (!_m && !_j && (_k = prefetcher_7.return)) yield _k.call(prefetcher_7);
|
|
440
|
-
}
|
|
441
|
-
finally { if (e_8) throw e_8.error; }
|
|
442
|
-
}
|
|
443
330
|
expect(callCount).toBe(0);
|
|
444
331
|
expect(loopCount).toBe(0);
|
|
445
332
|
expect(total).toBe(0);
|
|
446
333
|
expect(lastTotal).toBe(0);
|
|
447
|
-
})
|
|
448
|
-
it('empty async iterable works - async mapper', () =>
|
|
449
|
-
var _o, e_9, _p, _q;
|
|
334
|
+
});
|
|
335
|
+
it('empty async iterable works - async mapper', async () => {
|
|
450
336
|
let total = 0;
|
|
451
337
|
let callCount = 0;
|
|
452
338
|
const prefetcher = new iterable_mapper_1.IterableMapper((() => {
|
|
453
339
|
return {
|
|
454
340
|
[Symbol.asyncIterator]() {
|
|
455
341
|
return {
|
|
456
|
-
next() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return { value: undefined, done: true };
|
|
460
|
-
});
|
|
342
|
+
async next() {
|
|
343
|
+
await sleep(100);
|
|
344
|
+
return { value: undefined, done: true };
|
|
461
345
|
},
|
|
462
346
|
};
|
|
463
347
|
},
|
|
464
348
|
};
|
|
465
|
-
})(), (value) =>
|
|
466
|
-
|
|
349
|
+
})(), async (value) => {
|
|
350
|
+
await sleep(10);
|
|
467
351
|
callCount++;
|
|
468
352
|
total += value;
|
|
469
353
|
return total;
|
|
470
|
-
})
|
|
354
|
+
});
|
|
471
355
|
let lastTotal = 0;
|
|
472
356
|
let loopCount = 0;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const item = _q;
|
|
478
|
-
loopCount++;
|
|
479
|
-
if (item > lastTotal) {
|
|
480
|
-
lastTotal = item;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
485
|
-
finally {
|
|
486
|
-
try {
|
|
487
|
-
if (!_r && !_o && (_p = prefetcher_8.return)) yield _p.call(prefetcher_8);
|
|
357
|
+
for await (const item of prefetcher) {
|
|
358
|
+
loopCount++;
|
|
359
|
+
if (item > lastTotal) {
|
|
360
|
+
lastTotal = item;
|
|
488
361
|
}
|
|
489
|
-
finally { if (e_9) throw e_9.error; }
|
|
490
362
|
}
|
|
491
363
|
expect(callCount).toBe(0);
|
|
492
364
|
expect(loopCount).toBe(0);
|
|
493
365
|
expect(total).toBe(0);
|
|
494
366
|
expect(lastTotal).toBe(0);
|
|
495
|
-
})
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
describe('order preservation tests', () => {
|
|
370
|
+
it('preserves exact sequential order under high load with concurrency 1, maxUnread 8', async () => {
|
|
371
|
+
const size = 1000;
|
|
372
|
+
const input = Array.from({ length: size }, (_, i) => ({
|
|
373
|
+
value: i + 1,
|
|
374
|
+
ms: Math.floor(Math.random() * 20), // Random delay 0-19ms
|
|
375
|
+
}));
|
|
376
|
+
const mappedOrder = [];
|
|
377
|
+
const iteratedOrder = [];
|
|
378
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async ({ value, ms }) => {
|
|
379
|
+
await sleep(ms);
|
|
380
|
+
mappedOrder.push(value);
|
|
381
|
+
return value;
|
|
382
|
+
}, { concurrency: 1, maxUnread: 8 });
|
|
383
|
+
for await (const value of prefetcher) {
|
|
384
|
+
iteratedOrder.push(value);
|
|
385
|
+
// Add some random delay in consuming to create backpressure
|
|
386
|
+
await sleep(Math.floor(Math.random() * 20));
|
|
387
|
+
}
|
|
388
|
+
// Verify exact sequential order preservation
|
|
389
|
+
expect(iteratedOrder).toHaveLength(size);
|
|
390
|
+
expect(mappedOrder).toHaveLength(size);
|
|
391
|
+
// Verify that both mapped and iterated orders match the input sequence
|
|
392
|
+
const expectedOrder = Array.from({ length: size }, (_, i) => i + 1);
|
|
393
|
+
expect(mappedOrder).toEqual(expectedOrder);
|
|
394
|
+
expect(iteratedOrder).toEqual(expectedOrder);
|
|
395
|
+
}, 30000);
|
|
496
396
|
});
|
|
497
397
|
describe('concurrency 1, maxUnread 1', () => {
|
|
498
398
|
const concurrency = 1;
|
|
499
399
|
const maxUnread = 1;
|
|
500
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
501
|
-
const input = [1, () =>
|
|
400
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
401
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
502
402
|
const mappedValues = [];
|
|
503
403
|
const iteratedValues = [];
|
|
504
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
505
|
-
value = typeof value === 'function' ?
|
|
404
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
405
|
+
value = typeof value === 'function' ? await value() : value;
|
|
506
406
|
mappedValues.push(value);
|
|
507
407
|
if (value === 1) {
|
|
508
|
-
|
|
408
|
+
await sleep(100);
|
|
509
409
|
throw new Error('throw on 1st');
|
|
510
410
|
}
|
|
511
411
|
return value;
|
|
512
|
-
}
|
|
412
|
+
}, { concurrency, maxUnread });
|
|
513
413
|
let loopCount = 0;
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
_c = prefetcher_9_1.value;
|
|
519
|
-
_d = false;
|
|
520
|
-
const value = _c;
|
|
521
|
-
loopCount++;
|
|
522
|
-
iteratedValues.push(value);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
526
|
-
finally {
|
|
527
|
-
try {
|
|
528
|
-
if (!_d && !_a && (_b = prefetcher_9.return)) yield _b.call(prefetcher_9);
|
|
529
|
-
}
|
|
530
|
-
finally { if (e_10) throw e_10.error; }
|
|
414
|
+
await expect(async () => {
|
|
415
|
+
for await (const value of prefetcher) {
|
|
416
|
+
loopCount++;
|
|
417
|
+
iteratedValues.push(value);
|
|
531
418
|
}
|
|
532
|
-
})
|
|
533
|
-
|
|
419
|
+
}).rejects.toThrowError('throw on 1st');
|
|
420
|
+
await sleep(500);
|
|
534
421
|
expect(loopCount).toBe(0);
|
|
535
422
|
expect(mappedValues).toEqual([1]);
|
|
536
423
|
expect(iteratedValues).toEqual([]);
|
|
537
|
-
})
|
|
538
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
539
|
-
const input = [1, () =>
|
|
424
|
+
});
|
|
425
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
426
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
540
427
|
const mappedValues = [];
|
|
541
428
|
const iteratedValues = [];
|
|
542
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
543
|
-
value = typeof value === 'function' ?
|
|
429
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
430
|
+
value = typeof value === 'function' ? await value() : value;
|
|
544
431
|
mappedValues.push(value);
|
|
545
432
|
if (value === 2) {
|
|
546
433
|
throw new Error('throw on 2nd');
|
|
547
434
|
}
|
|
548
|
-
|
|
435
|
+
await sleep(100);
|
|
549
436
|
return value;
|
|
550
|
-
}
|
|
437
|
+
}, { concurrency, maxUnread });
|
|
551
438
|
let loopCount = 0;
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
_g = prefetcher_10_1.value;
|
|
557
|
-
_h = false;
|
|
558
|
-
const value = _g;
|
|
559
|
-
loopCount++;
|
|
560
|
-
iteratedValues.push(value);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
564
|
-
finally {
|
|
565
|
-
try {
|
|
566
|
-
if (!_h && !_e && (_f = prefetcher_10.return)) yield _f.call(prefetcher_10);
|
|
567
|
-
}
|
|
568
|
-
finally { if (e_11) throw e_11.error; }
|
|
439
|
+
await expect(async () => {
|
|
440
|
+
for await (const value of prefetcher) {
|
|
441
|
+
loopCount++;
|
|
442
|
+
iteratedValues.push(value);
|
|
569
443
|
}
|
|
570
|
-
})
|
|
571
|
-
|
|
444
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
445
|
+
await sleep(300);
|
|
572
446
|
expect(loopCount).toBe(1);
|
|
573
447
|
expect(mappedValues).toEqual([1, 2]);
|
|
574
448
|
expect(iteratedValues).toEqual([1]);
|
|
575
|
-
})
|
|
576
|
-
it('catches exception from mapper - 1st item - stopOnMapperError false', () =>
|
|
577
|
-
const input = [1, () =>
|
|
449
|
+
});
|
|
450
|
+
it('catches exception from mapper - 1st item - stopOnMapperError false', async () => {
|
|
451
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
578
452
|
const mappedValues = [];
|
|
579
453
|
const iteratedValues = [];
|
|
580
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
581
|
-
value = typeof value === 'function' ?
|
|
454
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
455
|
+
value = typeof value === 'function' ? await value() : value;
|
|
582
456
|
mappedValues.push(value);
|
|
583
457
|
if (value === 1) {
|
|
584
458
|
throw new Error('throw on 1st');
|
|
585
459
|
}
|
|
586
|
-
|
|
460
|
+
await sleep(100);
|
|
587
461
|
return value;
|
|
588
|
-
}
|
|
462
|
+
}, { concurrency: 1, stopOnMapperError: false });
|
|
589
463
|
let loopCount = 0;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
_l = prefetcher_11_1.value;
|
|
595
|
-
_m = false;
|
|
596
|
-
const value = _l;
|
|
597
|
-
loopCount++;
|
|
598
|
-
iteratedValues.push(value);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
602
|
-
finally {
|
|
603
|
-
try {
|
|
604
|
-
if (!_m && !_j && (_k = prefetcher_11.return)) yield _k.call(prefetcher_11);
|
|
605
|
-
}
|
|
606
|
-
finally { if (e_12) throw e_12.error; }
|
|
464
|
+
await expect(async () => {
|
|
465
|
+
for await (const value of prefetcher) {
|
|
466
|
+
loopCount++;
|
|
467
|
+
iteratedValues.push(value);
|
|
607
468
|
}
|
|
608
|
-
})
|
|
609
|
-
|
|
469
|
+
}).rejects.toThrowError('throw on 1st');
|
|
470
|
+
await sleep(300);
|
|
610
471
|
expect(loopCount).toBe(2);
|
|
611
472
|
expect(mappedValues).toEqual([1, 2, 3]);
|
|
612
473
|
expect(iteratedValues).toEqual([2, 3]);
|
|
613
|
-
})
|
|
614
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError false', () =>
|
|
615
|
-
const input = [1, () =>
|
|
474
|
+
});
|
|
475
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError false', async () => {
|
|
476
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
616
477
|
const mappedValues = [];
|
|
617
478
|
const iteratedValues = [];
|
|
618
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
619
|
-
value = typeof value === 'function' ?
|
|
479
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
480
|
+
value = typeof value === 'function' ? await value() : value;
|
|
620
481
|
mappedValues.push(value);
|
|
621
482
|
if (value === 2) {
|
|
622
483
|
throw new Error('throw on 2nd');
|
|
623
484
|
}
|
|
624
|
-
|
|
485
|
+
await sleep(100);
|
|
625
486
|
return value;
|
|
626
|
-
}
|
|
487
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
627
488
|
let loopCount = 0;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
_q = prefetcher_12_1.value;
|
|
633
|
-
_r = false;
|
|
634
|
-
const value = _q;
|
|
635
|
-
loopCount++;
|
|
636
|
-
iteratedValues.push(value);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
640
|
-
finally {
|
|
641
|
-
try {
|
|
642
|
-
if (!_r && !_o && (_p = prefetcher_12.return)) yield _p.call(prefetcher_12);
|
|
643
|
-
}
|
|
644
|
-
finally { if (e_13) throw e_13.error; }
|
|
489
|
+
await expect(async () => {
|
|
490
|
+
for await (const value of prefetcher) {
|
|
491
|
+
loopCount++;
|
|
492
|
+
iteratedValues.push(value);
|
|
645
493
|
}
|
|
646
|
-
})
|
|
647
|
-
|
|
494
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
495
|
+
await sleep(300);
|
|
648
496
|
expect(loopCount).toBe(2);
|
|
649
497
|
expect(mappedValues).toEqual([1, 2, 3]);
|
|
650
498
|
expect(iteratedValues).toEqual([1, 3]);
|
|
651
|
-
})
|
|
652
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
499
|
+
});
|
|
500
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
653
501
|
const input = new SleepIterator(10);
|
|
654
502
|
const mappedValues = [];
|
|
655
503
|
const iteratedValues = [];
|
|
@@ -658,30 +506,17 @@ describe('IterableMapper', () => {
|
|
|
658
506
|
throw new Error('throw on each');
|
|
659
507
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
660
508
|
let loopCount = 0;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
_u = prefetcher_13_1.value;
|
|
666
|
-
_v = false;
|
|
667
|
-
const value = _u;
|
|
668
|
-
loopCount++;
|
|
669
|
-
iteratedValues.push(value);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
673
|
-
finally {
|
|
674
|
-
try {
|
|
675
|
-
if (!_v && !_s && (_t = prefetcher_13.return)) yield _t.call(prefetcher_13);
|
|
676
|
-
}
|
|
677
|
-
finally { if (e_14) throw e_14.error; }
|
|
509
|
+
await expect(async () => {
|
|
510
|
+
for await (const value of prefetcher) {
|
|
511
|
+
loopCount++;
|
|
512
|
+
iteratedValues.push(value);
|
|
678
513
|
}
|
|
679
|
-
})
|
|
514
|
+
}).rejects.toThrowError('throw on each');
|
|
680
515
|
expect(loopCount).toBe(0);
|
|
681
516
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
682
517
|
expect(iteratedValues).toEqual([]);
|
|
683
|
-
})
|
|
684
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
518
|
+
});
|
|
519
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
685
520
|
const input = new SleepIterator(10);
|
|
686
521
|
const mappedValues = [];
|
|
687
522
|
const iteratedValues = [];
|
|
@@ -690,257 +525,166 @@ describe('IterableMapper', () => {
|
|
|
690
525
|
throw new Error('throw on each');
|
|
691
526
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
692
527
|
let loopCount = 0;
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
_y = prefetcher_14_1.value;
|
|
698
|
-
_z = false;
|
|
699
|
-
const value = _y;
|
|
700
|
-
loopCount++;
|
|
701
|
-
iteratedValues.push(value);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
705
|
-
finally {
|
|
706
|
-
try {
|
|
707
|
-
if (!_z && !_w && (_x = prefetcher_14.return)) yield _x.call(prefetcher_14);
|
|
708
|
-
}
|
|
709
|
-
finally { if (e_15) throw e_15.error; }
|
|
528
|
+
await expect(async () => {
|
|
529
|
+
for await (const value of prefetcher) {
|
|
530
|
+
loopCount++;
|
|
531
|
+
iteratedValues.push(value);
|
|
710
532
|
}
|
|
711
|
-
})
|
|
533
|
+
}).rejects.toThrowError('throw on each');
|
|
712
534
|
expect(loopCount).toBe(0);
|
|
713
535
|
expect(mappedValues).toEqual([1]);
|
|
714
536
|
expect(iteratedValues).toEqual([]);
|
|
715
|
-
})
|
|
716
|
-
it('catches exception from source iterator - 1st item', () =>
|
|
537
|
+
});
|
|
538
|
+
it('catches exception from source iterator - 1st item', async () => {
|
|
717
539
|
const input = new ThrowingIterator(100, 0, 100);
|
|
718
540
|
const mappedValues = [];
|
|
719
541
|
const iteratedValues = [];
|
|
720
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
542
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
721
543
|
mappedValues.push(value);
|
|
722
|
-
|
|
544
|
+
await sleep(100);
|
|
723
545
|
return value;
|
|
724
|
-
}
|
|
546
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
725
547
|
let loopCount = 0;
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
_2 = prefetcher_15_1.value;
|
|
731
|
-
_3 = false;
|
|
732
|
-
const value = _2;
|
|
733
|
-
loopCount++;
|
|
734
|
-
iteratedValues.push(value);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
738
|
-
finally {
|
|
739
|
-
try {
|
|
740
|
-
if (!_3 && !_0 && (_1 = prefetcher_15.return)) yield _1.call(prefetcher_15);
|
|
741
|
-
}
|
|
742
|
-
finally { if (e_16) throw e_16.error; }
|
|
548
|
+
await expect(async () => {
|
|
549
|
+
for await (const value of prefetcher) {
|
|
550
|
+
loopCount++;
|
|
551
|
+
iteratedValues.push(value);
|
|
743
552
|
}
|
|
744
|
-
})
|
|
745
|
-
|
|
553
|
+
}).rejects.toThrowError('throwing on index 0');
|
|
554
|
+
await sleep(500);
|
|
746
555
|
expect(loopCount).toBe(0);
|
|
747
556
|
expect(mappedValues).toEqual([]);
|
|
748
557
|
expect(iteratedValues).toEqual([]);
|
|
749
|
-
})
|
|
558
|
+
});
|
|
750
559
|
// The 2nd iterable item throwing is distinct from the 1st when concurrency is 1 because
|
|
751
560
|
// it means that the sourceNext() is invoked from next() or sourceNext() and not from
|
|
752
561
|
// the constructor
|
|
753
|
-
it('catches exception from source iterator - 2nd item', () =>
|
|
562
|
+
it('catches exception from source iterator - 2nd item', async () => {
|
|
754
563
|
const input = new ThrowingIterator(100, 1, 100);
|
|
755
564
|
const mappedValues = [];
|
|
756
565
|
const iteratedValues = [];
|
|
757
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
566
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
758
567
|
mappedValues.push(value);
|
|
759
|
-
|
|
568
|
+
await sleep(100);
|
|
760
569
|
return value;
|
|
761
|
-
}
|
|
570
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
762
571
|
let loopCount = 0;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
_6 = prefetcher_16_1.value;
|
|
768
|
-
_7 = false;
|
|
769
|
-
const value = _6;
|
|
770
|
-
loopCount++;
|
|
771
|
-
iteratedValues.push(value);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
775
|
-
finally {
|
|
776
|
-
try {
|
|
777
|
-
if (!_7 && !_4 && (_5 = prefetcher_16.return)) yield _5.call(prefetcher_16);
|
|
778
|
-
}
|
|
779
|
-
finally { if (e_17) throw e_17.error; }
|
|
572
|
+
await expect(async () => {
|
|
573
|
+
for await (const value of prefetcher) {
|
|
574
|
+
loopCount++;
|
|
575
|
+
iteratedValues.push(value);
|
|
780
576
|
}
|
|
781
|
-
})
|
|
782
|
-
|
|
577
|
+
}).rejects.toThrowError('throwing on index 1');
|
|
578
|
+
await sleep(500);
|
|
783
579
|
expect(loopCount).toBe(1);
|
|
784
580
|
expect(mappedValues).toEqual([0]);
|
|
785
581
|
expect(iteratedValues).toEqual([0]);
|
|
786
|
-
})
|
|
582
|
+
});
|
|
787
583
|
});
|
|
788
584
|
describe('concurrency 2, maxUnread 4', () => {
|
|
789
585
|
const concurrency = 2;
|
|
790
586
|
const maxUnread = 4;
|
|
791
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
792
|
-
const input = [1, () =>
|
|
587
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
588
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
793
589
|
const mappedValues = [];
|
|
794
590
|
const iteratedValues = [];
|
|
795
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
796
|
-
value = typeof value === 'function' ?
|
|
591
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
592
|
+
value = typeof value === 'function' ? await value() : value;
|
|
797
593
|
mappedValues.push(value);
|
|
798
594
|
if (value === 1) {
|
|
799
|
-
|
|
595
|
+
await sleep(100);
|
|
800
596
|
throw new Error('throw on 1st');
|
|
801
597
|
}
|
|
802
598
|
return value;
|
|
803
|
-
}
|
|
599
|
+
}, { concurrency, maxUnread });
|
|
804
600
|
let loopCount = 0;
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
_c = prefetcher_17_1.value;
|
|
810
|
-
_d = false;
|
|
811
|
-
const value = _c;
|
|
812
|
-
loopCount++;
|
|
813
|
-
iteratedValues.push(value);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
817
|
-
finally {
|
|
818
|
-
try {
|
|
819
|
-
if (!_d && !_a && (_b = prefetcher_17.return)) yield _b.call(prefetcher_17);
|
|
820
|
-
}
|
|
821
|
-
finally { if (e_18) throw e_18.error; }
|
|
601
|
+
await expect(async () => {
|
|
602
|
+
for await (const value of prefetcher) {
|
|
603
|
+
loopCount++;
|
|
604
|
+
iteratedValues.push(value);
|
|
822
605
|
}
|
|
823
|
-
})
|
|
824
|
-
|
|
606
|
+
}).rejects.toThrowError('throw on 1st');
|
|
607
|
+
await sleep(500);
|
|
825
608
|
expect(loopCount).toBe(0);
|
|
826
609
|
expect(mappedValues).toEqual([1, 2]);
|
|
827
610
|
expect(iteratedValues).toEqual([]);
|
|
828
|
-
})
|
|
829
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
830
|
-
const input = [1, () =>
|
|
611
|
+
});
|
|
612
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
613
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
831
614
|
const mappedValues = [];
|
|
832
615
|
const iteratedValues = [];
|
|
833
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
834
|
-
value = typeof value === 'function' ?
|
|
616
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
617
|
+
value = typeof value === 'function' ? await value() : value;
|
|
835
618
|
mappedValues.push(value);
|
|
836
619
|
if (value === 2) {
|
|
837
620
|
throw new Error('throw on 2nd');
|
|
838
621
|
}
|
|
839
|
-
|
|
622
|
+
await sleep(100);
|
|
840
623
|
return value;
|
|
841
|
-
}
|
|
624
|
+
}, { concurrency, maxUnread });
|
|
842
625
|
let loopCount = 0;
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
_g = prefetcher_18_1.value;
|
|
848
|
-
_h = false;
|
|
849
|
-
const value = _g;
|
|
850
|
-
loopCount++;
|
|
851
|
-
iteratedValues.push(value);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
855
|
-
finally {
|
|
856
|
-
try {
|
|
857
|
-
if (!_h && !_e && (_f = prefetcher_18.return)) yield _f.call(prefetcher_18);
|
|
858
|
-
}
|
|
859
|
-
finally { if (e_19) throw e_19.error; }
|
|
626
|
+
await expect(async () => {
|
|
627
|
+
for await (const value of prefetcher) {
|
|
628
|
+
loopCount++;
|
|
629
|
+
iteratedValues.push(value);
|
|
860
630
|
}
|
|
861
|
-
})
|
|
862
|
-
|
|
631
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
632
|
+
await sleep(300);
|
|
863
633
|
expect(loopCount).toBe(2);
|
|
864
634
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
865
635
|
expect(iteratedValues).toEqual([1, 3]);
|
|
866
|
-
})
|
|
867
|
-
it('catches exception from mapper - 1st item - stopOnMapperError false', () =>
|
|
868
|
-
const input = [1, () =>
|
|
636
|
+
});
|
|
637
|
+
it('catches exception from mapper - 1st item - stopOnMapperError false', async () => {
|
|
638
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
869
639
|
const mappedValues = [];
|
|
870
640
|
const iteratedValues = [];
|
|
871
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
872
|
-
value = typeof value === 'function' ?
|
|
641
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
642
|
+
value = typeof value === 'function' ? await value() : value;
|
|
873
643
|
mappedValues.push(value);
|
|
874
644
|
if (value === 1) {
|
|
875
645
|
throw new Error('throw on 1st');
|
|
876
646
|
}
|
|
877
|
-
|
|
647
|
+
await sleep(100);
|
|
878
648
|
return value;
|
|
879
|
-
}
|
|
649
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
880
650
|
let loopCount = 0;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
_l = prefetcher_19_1.value;
|
|
886
|
-
_m = false;
|
|
887
|
-
const value = _l;
|
|
888
|
-
loopCount++;
|
|
889
|
-
iteratedValues.push(value);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
893
|
-
finally {
|
|
894
|
-
try {
|
|
895
|
-
if (!_m && !_j && (_k = prefetcher_19.return)) yield _k.call(prefetcher_19);
|
|
896
|
-
}
|
|
897
|
-
finally { if (e_20) throw e_20.error; }
|
|
651
|
+
await expect(async () => {
|
|
652
|
+
for await (const value of prefetcher) {
|
|
653
|
+
loopCount++;
|
|
654
|
+
iteratedValues.push(value);
|
|
898
655
|
}
|
|
899
|
-
})
|
|
900
|
-
|
|
656
|
+
}).rejects.toThrowError('throw on 1st');
|
|
657
|
+
await sleep(300);
|
|
901
658
|
expect(loopCount).toBe(2);
|
|
902
659
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
903
660
|
expect(iteratedValues).toEqual([3, 2]);
|
|
904
|
-
})
|
|
905
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError false', () =>
|
|
906
|
-
const input = [1, () =>
|
|
661
|
+
});
|
|
662
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError false', async () => {
|
|
663
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
907
664
|
const mappedValues = [];
|
|
908
665
|
const iteratedValues = [];
|
|
909
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
910
|
-
value = typeof value === 'function' ?
|
|
666
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
667
|
+
value = typeof value === 'function' ? await value() : value;
|
|
911
668
|
mappedValues.push(value);
|
|
912
669
|
if (value === 2) {
|
|
913
670
|
throw new Error('throw on 2nd');
|
|
914
671
|
}
|
|
915
|
-
|
|
672
|
+
await sleep(100);
|
|
916
673
|
return value;
|
|
917
|
-
}
|
|
674
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
918
675
|
let loopCount = 0;
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
_q = prefetcher_20_1.value;
|
|
924
|
-
_r = false;
|
|
925
|
-
const value = _q;
|
|
926
|
-
loopCount++;
|
|
927
|
-
iteratedValues.push(value);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
931
|
-
finally {
|
|
932
|
-
try {
|
|
933
|
-
if (!_r && !_o && (_p = prefetcher_20.return)) yield _p.call(prefetcher_20);
|
|
934
|
-
}
|
|
935
|
-
finally { if (e_21) throw e_21.error; }
|
|
676
|
+
await expect(async () => {
|
|
677
|
+
for await (const value of prefetcher) {
|
|
678
|
+
loopCount++;
|
|
679
|
+
iteratedValues.push(value);
|
|
936
680
|
}
|
|
937
|
-
})
|
|
938
|
-
|
|
681
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
682
|
+
await sleep(300);
|
|
939
683
|
expect(loopCount).toBe(2);
|
|
940
684
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
941
685
|
expect(iteratedValues).toEqual([1, 3]);
|
|
942
|
-
})
|
|
943
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
686
|
+
});
|
|
687
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
944
688
|
const input = new SleepIterator(10);
|
|
945
689
|
const mappedValues = [];
|
|
946
690
|
const iteratedValues = [];
|
|
@@ -949,30 +693,17 @@ describe('IterableMapper', () => {
|
|
|
949
693
|
throw new Error('throw on each');
|
|
950
694
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
951
695
|
let loopCount = 0;
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
_u = prefetcher_21_1.value;
|
|
957
|
-
_v = false;
|
|
958
|
-
const value = _u;
|
|
959
|
-
loopCount++;
|
|
960
|
-
iteratedValues.push(value);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
964
|
-
finally {
|
|
965
|
-
try {
|
|
966
|
-
if (!_v && !_s && (_t = prefetcher_21.return)) yield _t.call(prefetcher_21);
|
|
967
|
-
}
|
|
968
|
-
finally { if (e_22) throw e_22.error; }
|
|
696
|
+
await expect(async () => {
|
|
697
|
+
for await (const value of prefetcher) {
|
|
698
|
+
loopCount++;
|
|
699
|
+
iteratedValues.push(value);
|
|
969
700
|
}
|
|
970
|
-
})
|
|
701
|
+
}).rejects.toThrowError('throw on each');
|
|
971
702
|
expect(loopCount).toBe(0);
|
|
972
703
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
973
704
|
expect(iteratedValues).toEqual([]);
|
|
974
|
-
})
|
|
975
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
705
|
+
});
|
|
706
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
976
707
|
const input = new SleepIterator(10);
|
|
977
708
|
const mappedValues = [];
|
|
978
709
|
const iteratedValues = [];
|
|
@@ -981,138 +712,86 @@ describe('IterableMapper', () => {
|
|
|
981
712
|
throw new Error('throw on each');
|
|
982
713
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
983
714
|
let loopCount = 0;
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
_y = prefetcher_22_1.value;
|
|
989
|
-
_z = false;
|
|
990
|
-
const value = _y;
|
|
991
|
-
loopCount++;
|
|
992
|
-
iteratedValues.push(value);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
996
|
-
finally {
|
|
997
|
-
try {
|
|
998
|
-
if (!_z && !_w && (_x = prefetcher_22.return)) yield _x.call(prefetcher_22);
|
|
999
|
-
}
|
|
1000
|
-
finally { if (e_23) throw e_23.error; }
|
|
715
|
+
await expect(async () => {
|
|
716
|
+
for await (const value of prefetcher) {
|
|
717
|
+
loopCount++;
|
|
718
|
+
iteratedValues.push(value);
|
|
1001
719
|
}
|
|
1002
|
-
})
|
|
720
|
+
}).rejects.toThrowError('throw on each');
|
|
1003
721
|
expect(loopCount).toBe(0);
|
|
1004
722
|
expect(mappedValues).toEqual([1]);
|
|
1005
723
|
expect(iteratedValues).toEqual([]);
|
|
1006
|
-
})
|
|
1007
|
-
it('catches exception from source iterator - 1st item', () =>
|
|
724
|
+
});
|
|
725
|
+
it('catches exception from source iterator - 1st item', async () => {
|
|
1008
726
|
const input = new ThrowingIterator(100, 0, 100);
|
|
1009
727
|
const mappedValues = [];
|
|
1010
728
|
const iteratedValues = [];
|
|
1011
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
729
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
1012
730
|
mappedValues.push(value);
|
|
1013
|
-
|
|
731
|
+
await sleep(100);
|
|
1014
732
|
return value;
|
|
1015
|
-
}
|
|
733
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1016
734
|
let loopCount = 0;
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
_2 = prefetcher_23_1.value;
|
|
1022
|
-
_3 = false;
|
|
1023
|
-
const value = _2;
|
|
1024
|
-
loopCount++;
|
|
1025
|
-
iteratedValues.push(value);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
1029
|
-
finally {
|
|
1030
|
-
try {
|
|
1031
|
-
if (!_3 && !_0 && (_1 = prefetcher_23.return)) yield _1.call(prefetcher_23);
|
|
1032
|
-
}
|
|
1033
|
-
finally { if (e_24) throw e_24.error; }
|
|
735
|
+
await expect(async () => {
|
|
736
|
+
for await (const value of prefetcher) {
|
|
737
|
+
loopCount++;
|
|
738
|
+
iteratedValues.push(value);
|
|
1034
739
|
}
|
|
1035
|
-
})
|
|
1036
|
-
|
|
740
|
+
}).rejects.toThrowError('throwing on index 0');
|
|
741
|
+
await sleep(500);
|
|
1037
742
|
expect(loopCount).toBe(0);
|
|
1038
743
|
expect(mappedValues).toEqual([]);
|
|
1039
744
|
expect(iteratedValues).toEqual([]);
|
|
1040
|
-
})
|
|
745
|
+
});
|
|
1041
746
|
// The 2nd iterable item throwing is distinct from the 1st when concurrency is 1 because
|
|
1042
747
|
// it means that the sourceNext() is invoked from next() or sourceNext() and not from
|
|
1043
748
|
// the constructor
|
|
1044
|
-
it('catches exception from source iterator - 2nd item', () =>
|
|
749
|
+
it('catches exception from source iterator - 2nd item', async () => {
|
|
1045
750
|
const input = new ThrowingIterator(100, 1, 100);
|
|
1046
751
|
const mappedValues = [];
|
|
1047
752
|
const iteratedValues = [];
|
|
1048
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
753
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
1049
754
|
mappedValues.push(value);
|
|
1050
|
-
|
|
755
|
+
await sleep(100);
|
|
1051
756
|
return value;
|
|
1052
|
-
}
|
|
757
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1053
758
|
let loopCount = 0;
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
_6 = prefetcher_24_1.value;
|
|
1059
|
-
_7 = false;
|
|
1060
|
-
const value = _6;
|
|
1061
|
-
loopCount++;
|
|
1062
|
-
iteratedValues.push(value);
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
catch (e_25_1) { e_25 = { error: e_25_1 }; }
|
|
1066
|
-
finally {
|
|
1067
|
-
try {
|
|
1068
|
-
if (!_7 && !_4 && (_5 = prefetcher_24.return)) yield _5.call(prefetcher_24);
|
|
1069
|
-
}
|
|
1070
|
-
finally { if (e_25) throw e_25.error; }
|
|
759
|
+
await expect(async () => {
|
|
760
|
+
for await (const value of prefetcher) {
|
|
761
|
+
loopCount++;
|
|
762
|
+
iteratedValues.push(value);
|
|
1071
763
|
}
|
|
1072
|
-
})
|
|
1073
|
-
|
|
764
|
+
}).rejects.toThrowError('throwing on index 1');
|
|
765
|
+
await sleep(500);
|
|
1074
766
|
expect(loopCount).toBe(1);
|
|
1075
767
|
expect(mappedValues).toEqual([0]);
|
|
1076
768
|
expect(iteratedValues).toEqual([0]);
|
|
1077
|
-
})
|
|
769
|
+
});
|
|
1078
770
|
});
|
|
1079
771
|
describe('concurrency Number.POSITIVE_INFINITY, maxUnread Number.POSITIVE_INFINITY', () => {
|
|
1080
772
|
const concurrency = Number.POSITIVE_INFINITY;
|
|
1081
773
|
const maxUnread = Number.POSITIVE_INFINITY;
|
|
1082
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
1083
|
-
const input = [1, () =>
|
|
774
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
775
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
1084
776
|
const mappedValues = [];
|
|
1085
777
|
const iteratedValues = [];
|
|
1086
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
1087
|
-
value = typeof value === 'function' ?
|
|
778
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
779
|
+
value = typeof value === 'function' ? await value() : value;
|
|
1088
780
|
mappedValues.push(value);
|
|
1089
781
|
if (value === 1) {
|
|
1090
|
-
|
|
782
|
+
await sleep(100);
|
|
1091
783
|
throw new Error('throw on 1st');
|
|
1092
784
|
}
|
|
1093
785
|
return value;
|
|
1094
|
-
}
|
|
786
|
+
}, { concurrency, maxUnread });
|
|
1095
787
|
let loopCount = 0;
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
_c = prefetcher_25_1.value;
|
|
1101
|
-
_d = false;
|
|
1102
|
-
const value = _c;
|
|
1103
|
-
loopCount++;
|
|
1104
|
-
iteratedValues.push(value);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
1108
|
-
finally {
|
|
1109
|
-
try {
|
|
1110
|
-
if (!_d && !_a && (_b = prefetcher_25.return)) yield _b.call(prefetcher_25);
|
|
1111
|
-
}
|
|
1112
|
-
finally { if (e_26) throw e_26.error; }
|
|
788
|
+
await expect(async () => {
|
|
789
|
+
for await (const value of prefetcher) {
|
|
790
|
+
loopCount++;
|
|
791
|
+
iteratedValues.push(value);
|
|
1113
792
|
}
|
|
1114
|
-
})
|
|
1115
|
-
|
|
793
|
+
}).rejects.toThrowError('throw on 1st');
|
|
794
|
+
await sleep(500);
|
|
1116
795
|
expect(loopCount).toBe(1);
|
|
1117
796
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
1118
797
|
// NOTE: This seems wrong - Item 2 succeeds at being mapped, but after the 1st item throws.
|
|
@@ -1126,83 +805,57 @@ describe('IterableMapper', () => {
|
|
|
1126
805
|
// then this behavior would match their results exactly (the 1st item would cause the iteration
|
|
1127
806
|
// loop to break out).
|
|
1128
807
|
expect(iteratedValues).toEqual([3]);
|
|
1129
|
-
})
|
|
1130
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
1131
|
-
const input = [1, () =>
|
|
808
|
+
});
|
|
809
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
810
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
1132
811
|
const mappedValues = [];
|
|
1133
812
|
const iteratedValues = [];
|
|
1134
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
1135
|
-
value = typeof value === 'function' ?
|
|
813
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
814
|
+
value = typeof value === 'function' ? await value() : value;
|
|
1136
815
|
mappedValues.push(value);
|
|
1137
816
|
if (value === 2) {
|
|
1138
817
|
throw new Error('throw on 2nd');
|
|
1139
818
|
}
|
|
1140
|
-
|
|
819
|
+
await sleep(100);
|
|
1141
820
|
return value;
|
|
1142
|
-
}
|
|
821
|
+
}, { concurrency, maxUnread });
|
|
1143
822
|
let loopCount = 0;
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
_g = prefetcher_26_1.value;
|
|
1149
|
-
_h = false;
|
|
1150
|
-
const value = _g;
|
|
1151
|
-
loopCount++;
|
|
1152
|
-
iteratedValues.push(value);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
1156
|
-
finally {
|
|
1157
|
-
try {
|
|
1158
|
-
if (!_h && !_e && (_f = prefetcher_26.return)) yield _f.call(prefetcher_26);
|
|
1159
|
-
}
|
|
1160
|
-
finally { if (e_27) throw e_27.error; }
|
|
823
|
+
await expect(async () => {
|
|
824
|
+
for await (const value of prefetcher) {
|
|
825
|
+
loopCount++;
|
|
826
|
+
iteratedValues.push(value);
|
|
1161
827
|
}
|
|
1162
|
-
})
|
|
1163
|
-
|
|
828
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
829
|
+
await sleep(300);
|
|
1164
830
|
expect(loopCount).toBe(2);
|
|
1165
831
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
1166
832
|
expect(iteratedValues).toEqual([1, 3]);
|
|
1167
|
-
})
|
|
1168
|
-
it('async mapper works', () =>
|
|
1169
|
-
var _j, e_28, _k, _l;
|
|
833
|
+
});
|
|
834
|
+
it('async mapper works', async () => {
|
|
1170
835
|
const max = 100;
|
|
1171
836
|
const iterator = new SleepIterator(max);
|
|
1172
837
|
let total = 0;
|
|
1173
838
|
let callCount = 0;
|
|
1174
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, (value) =>
|
|
839
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, async (value) => {
|
|
1175
840
|
callCount++;
|
|
1176
841
|
total += value;
|
|
1177
|
-
|
|
842
|
+
await sleep(10 * (callCount % 6));
|
|
1178
843
|
return total;
|
|
1179
|
-
}
|
|
844
|
+
}, { concurrency, maxUnread });
|
|
1180
845
|
let lastTotal = 0;
|
|
1181
846
|
let loopCount = 0;
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const item = _l;
|
|
1187
|
-
loopCount++;
|
|
1188
|
-
if (item > lastTotal) {
|
|
1189
|
-
lastTotal = item;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
catch (e_28_1) { e_28 = { error: e_28_1 }; }
|
|
1194
|
-
finally {
|
|
1195
|
-
try {
|
|
1196
|
-
if (!_m && !_j && (_k = prefetcher_27.return)) yield _k.call(prefetcher_27);
|
|
847
|
+
for await (const item of prefetcher) {
|
|
848
|
+
loopCount++;
|
|
849
|
+
if (item > lastTotal) {
|
|
850
|
+
lastTotal = item;
|
|
1197
851
|
}
|
|
1198
|
-
finally { if (e_28) throw e_28.error; }
|
|
1199
852
|
}
|
|
1200
853
|
expect(callCount).toBe(max);
|
|
1201
854
|
expect(loopCount).toBe(max);
|
|
1202
855
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
1203
856
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
1204
|
-
})
|
|
1205
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
857
|
+
});
|
|
858
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
1206
859
|
const input = new SleepIterator(10);
|
|
1207
860
|
const mappedValues = [];
|
|
1208
861
|
const iteratedValues = [];
|
|
@@ -1211,30 +864,17 @@ describe('IterableMapper', () => {
|
|
|
1211
864
|
throw new Error('throw on each');
|
|
1212
865
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
1213
866
|
let loopCount = 0;
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
_q = prefetcher_28_1.value;
|
|
1219
|
-
_r = false;
|
|
1220
|
-
const value = _q;
|
|
1221
|
-
loopCount++;
|
|
1222
|
-
iteratedValues.push(value);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
1226
|
-
finally {
|
|
1227
|
-
try {
|
|
1228
|
-
if (!_r && !_o && (_p = prefetcher_28.return)) yield _p.call(prefetcher_28);
|
|
1229
|
-
}
|
|
1230
|
-
finally { if (e_29) throw e_29.error; }
|
|
867
|
+
await expect(async () => {
|
|
868
|
+
for await (const value of prefetcher) {
|
|
869
|
+
loopCount++;
|
|
870
|
+
iteratedValues.push(value);
|
|
1231
871
|
}
|
|
1232
|
-
})
|
|
872
|
+
}).rejects.toThrowError('throw on each');
|
|
1233
873
|
expect(loopCount).toBe(0);
|
|
1234
874
|
expect(mappedValues).toEqual([1]);
|
|
1235
875
|
expect(iteratedValues).toEqual([]);
|
|
1236
|
-
})
|
|
1237
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
876
|
+
});
|
|
877
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
1238
878
|
const input = new SleepIterator(10);
|
|
1239
879
|
const mappedValues = [];
|
|
1240
880
|
const iteratedValues = [];
|
|
@@ -1243,29 +883,16 @@ describe('IterableMapper', () => {
|
|
|
1243
883
|
throw new Error('throw on each');
|
|
1244
884
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1245
885
|
let loopCount = 0;
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
_u = prefetcher_29_1.value;
|
|
1251
|
-
_v = false;
|
|
1252
|
-
const value = _u;
|
|
1253
|
-
loopCount++;
|
|
1254
|
-
iteratedValues.push(value);
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
catch (e_30_1) { e_30 = { error: e_30_1 }; }
|
|
1258
|
-
finally {
|
|
1259
|
-
try {
|
|
1260
|
-
if (!_v && !_s && (_t = prefetcher_29.return)) yield _t.call(prefetcher_29);
|
|
1261
|
-
}
|
|
1262
|
-
finally { if (e_30) throw e_30.error; }
|
|
886
|
+
await expect(async () => {
|
|
887
|
+
for await (const value of prefetcher) {
|
|
888
|
+
loopCount++;
|
|
889
|
+
iteratedValues.push(value);
|
|
1263
890
|
}
|
|
1264
|
-
})
|
|
891
|
+
}).rejects.toThrowError('throw on each');
|
|
1265
892
|
expect(loopCount).toBe(0);
|
|
1266
893
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
1267
894
|
expect(iteratedValues).toEqual([]);
|
|
1268
|
-
})
|
|
895
|
+
});
|
|
1269
896
|
});
|
|
1270
897
|
});
|
|
1271
898
|
//# sourceMappingURL=iterable-mapper.test.js.map
|