@shutterstock/p-map-iterable 1.0.10 → 1.1.0
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 +5 -2
- package/dist/src/blocking-queue.js +61 -70
- package/dist/src/blocking-queue.js.map +1 -1
- package/dist/src/blocking-queue.test.js +68 -69
- package/dist/src/blocking-queue.test.js.map +1 -1
- package/dist/src/iterable-mapper.d.ts.map +1 -1
- package/dist/src/iterable-mapper.js +112 -116
- package/dist/src/iterable-mapper.js.map +1 -1
- package/dist/src/iterable-mapper.test.js +319 -720
- package/dist/src/iterable-mapper.test.js.map +1 -1
- package/dist/src/iterable-queue-mapper-simple.js +27 -36
- 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.js +4 -9
- package/dist/src/iterable-queue-mapper.js.map +1 -1
- package/dist/src/iterable-queue-mapper.test.js +35 -77
- 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 +42 -121
- package/dist/src/iterable-queue.test.js.map +1 -1
- package/package.json +11 -6
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -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,155 @@ 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
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
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);
|
|
324
|
+
for await (const item of prefetcher) {
|
|
325
|
+
loopCount++;
|
|
326
|
+
if (item > lastTotal) {
|
|
327
|
+
lastTotal = item;
|
|
440
328
|
}
|
|
441
|
-
finally { if (e_8) throw e_8.error; }
|
|
442
329
|
}
|
|
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
|
-
}
|
|
357
|
+
for await (const item of prefetcher) {
|
|
358
|
+
loopCount++;
|
|
359
|
+
if (item > lastTotal) {
|
|
360
|
+
lastTotal = item;
|
|
482
361
|
}
|
|
483
362
|
}
|
|
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);
|
|
488
|
-
}
|
|
489
|
-
finally { if (e_9) throw e_9.error; }
|
|
490
|
-
}
|
|
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
|
+
});
|
|
496
368
|
});
|
|
497
369
|
describe('concurrency 1, maxUnread 1', () => {
|
|
498
370
|
const concurrency = 1;
|
|
499
371
|
const maxUnread = 1;
|
|
500
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
501
|
-
const input = [1, () =>
|
|
372
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
373
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
502
374
|
const mappedValues = [];
|
|
503
375
|
const iteratedValues = [];
|
|
504
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
505
|
-
value = typeof value === 'function' ?
|
|
376
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
377
|
+
value = typeof value === 'function' ? await value() : value;
|
|
506
378
|
mappedValues.push(value);
|
|
507
379
|
if (value === 1) {
|
|
508
|
-
|
|
380
|
+
await sleep(100);
|
|
509
381
|
throw new Error('throw on 1st');
|
|
510
382
|
}
|
|
511
383
|
return value;
|
|
512
|
-
}
|
|
384
|
+
}, { concurrency, maxUnread });
|
|
513
385
|
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; }
|
|
386
|
+
await expect(async () => {
|
|
387
|
+
for await (const value of prefetcher) {
|
|
388
|
+
loopCount++;
|
|
389
|
+
iteratedValues.push(value);
|
|
531
390
|
}
|
|
532
|
-
})
|
|
533
|
-
|
|
391
|
+
}).rejects.toThrowError('throw on 1st');
|
|
392
|
+
await sleep(500);
|
|
534
393
|
expect(loopCount).toBe(0);
|
|
535
394
|
expect(mappedValues).toEqual([1]);
|
|
536
395
|
expect(iteratedValues).toEqual([]);
|
|
537
|
-
})
|
|
538
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
539
|
-
const input = [1, () =>
|
|
396
|
+
});
|
|
397
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
398
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
540
399
|
const mappedValues = [];
|
|
541
400
|
const iteratedValues = [];
|
|
542
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
543
|
-
value = typeof value === 'function' ?
|
|
401
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
402
|
+
value = typeof value === 'function' ? await value() : value;
|
|
544
403
|
mappedValues.push(value);
|
|
545
404
|
if (value === 2) {
|
|
546
405
|
throw new Error('throw on 2nd');
|
|
547
406
|
}
|
|
548
|
-
|
|
407
|
+
await sleep(100);
|
|
549
408
|
return value;
|
|
550
|
-
}
|
|
409
|
+
}, { concurrency, maxUnread });
|
|
551
410
|
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; }
|
|
411
|
+
await expect(async () => {
|
|
412
|
+
for await (const value of prefetcher) {
|
|
413
|
+
loopCount++;
|
|
414
|
+
iteratedValues.push(value);
|
|
569
415
|
}
|
|
570
|
-
})
|
|
571
|
-
|
|
416
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
417
|
+
await sleep(300);
|
|
572
418
|
expect(loopCount).toBe(1);
|
|
573
419
|
expect(mappedValues).toEqual([1, 2]);
|
|
574
420
|
expect(iteratedValues).toEqual([1]);
|
|
575
|
-
})
|
|
576
|
-
it('catches exception from mapper - 1st item - stopOnMapperError false', () =>
|
|
577
|
-
const input = [1, () =>
|
|
421
|
+
});
|
|
422
|
+
it('catches exception from mapper - 1st item - stopOnMapperError false', async () => {
|
|
423
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
578
424
|
const mappedValues = [];
|
|
579
425
|
const iteratedValues = [];
|
|
580
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
581
|
-
value = typeof value === 'function' ?
|
|
426
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
427
|
+
value = typeof value === 'function' ? await value() : value;
|
|
582
428
|
mappedValues.push(value);
|
|
583
429
|
if (value === 1) {
|
|
584
430
|
throw new Error('throw on 1st');
|
|
585
431
|
}
|
|
586
|
-
|
|
432
|
+
await sleep(100);
|
|
587
433
|
return value;
|
|
588
|
-
}
|
|
434
|
+
}, { concurrency: 1, stopOnMapperError: false });
|
|
589
435
|
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; }
|
|
436
|
+
await expect(async () => {
|
|
437
|
+
for await (const value of prefetcher) {
|
|
438
|
+
loopCount++;
|
|
439
|
+
iteratedValues.push(value);
|
|
607
440
|
}
|
|
608
|
-
})
|
|
609
|
-
|
|
441
|
+
}).rejects.toThrowError('throw on 1st');
|
|
442
|
+
await sleep(300);
|
|
610
443
|
expect(loopCount).toBe(2);
|
|
611
444
|
expect(mappedValues).toEqual([1, 2, 3]);
|
|
612
445
|
expect(iteratedValues).toEqual([2, 3]);
|
|
613
|
-
})
|
|
614
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError false', () =>
|
|
615
|
-
const input = [1, () =>
|
|
446
|
+
});
|
|
447
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError false', async () => {
|
|
448
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
616
449
|
const mappedValues = [];
|
|
617
450
|
const iteratedValues = [];
|
|
618
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
619
|
-
value = typeof value === 'function' ?
|
|
451
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
452
|
+
value = typeof value === 'function' ? await value() : value;
|
|
620
453
|
mappedValues.push(value);
|
|
621
454
|
if (value === 2) {
|
|
622
455
|
throw new Error('throw on 2nd');
|
|
623
456
|
}
|
|
624
|
-
|
|
457
|
+
await sleep(100);
|
|
625
458
|
return value;
|
|
626
|
-
}
|
|
459
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
627
460
|
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; }
|
|
461
|
+
await expect(async () => {
|
|
462
|
+
for await (const value of prefetcher) {
|
|
463
|
+
loopCount++;
|
|
464
|
+
iteratedValues.push(value);
|
|
645
465
|
}
|
|
646
|
-
})
|
|
647
|
-
|
|
466
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
467
|
+
await sleep(300);
|
|
648
468
|
expect(loopCount).toBe(2);
|
|
649
469
|
expect(mappedValues).toEqual([1, 2, 3]);
|
|
650
470
|
expect(iteratedValues).toEqual([1, 3]);
|
|
651
|
-
})
|
|
652
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
471
|
+
});
|
|
472
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
653
473
|
const input = new SleepIterator(10);
|
|
654
474
|
const mappedValues = [];
|
|
655
475
|
const iteratedValues = [];
|
|
@@ -658,30 +478,17 @@ describe('IterableMapper', () => {
|
|
|
658
478
|
throw new Error('throw on each');
|
|
659
479
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
660
480
|
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; }
|
|
481
|
+
await expect(async () => {
|
|
482
|
+
for await (const value of prefetcher) {
|
|
483
|
+
loopCount++;
|
|
484
|
+
iteratedValues.push(value);
|
|
678
485
|
}
|
|
679
|
-
})
|
|
486
|
+
}).rejects.toThrowError('throw on each');
|
|
680
487
|
expect(loopCount).toBe(0);
|
|
681
488
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
682
489
|
expect(iteratedValues).toEqual([]);
|
|
683
|
-
})
|
|
684
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
490
|
+
});
|
|
491
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
685
492
|
const input = new SleepIterator(10);
|
|
686
493
|
const mappedValues = [];
|
|
687
494
|
const iteratedValues = [];
|
|
@@ -690,257 +497,166 @@ describe('IterableMapper', () => {
|
|
|
690
497
|
throw new Error('throw on each');
|
|
691
498
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
692
499
|
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; }
|
|
500
|
+
await expect(async () => {
|
|
501
|
+
for await (const value of prefetcher) {
|
|
502
|
+
loopCount++;
|
|
503
|
+
iteratedValues.push(value);
|
|
710
504
|
}
|
|
711
|
-
})
|
|
505
|
+
}).rejects.toThrowError('throw on each');
|
|
712
506
|
expect(loopCount).toBe(0);
|
|
713
507
|
expect(mappedValues).toEqual([1]);
|
|
714
508
|
expect(iteratedValues).toEqual([]);
|
|
715
|
-
})
|
|
716
|
-
it('catches exception from source iterator - 1st item', () =>
|
|
509
|
+
});
|
|
510
|
+
it('catches exception from source iterator - 1st item', async () => {
|
|
717
511
|
const input = new ThrowingIterator(100, 0, 100);
|
|
718
512
|
const mappedValues = [];
|
|
719
513
|
const iteratedValues = [];
|
|
720
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
514
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
721
515
|
mappedValues.push(value);
|
|
722
|
-
|
|
516
|
+
await sleep(100);
|
|
723
517
|
return value;
|
|
724
|
-
}
|
|
518
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
725
519
|
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; }
|
|
520
|
+
await expect(async () => {
|
|
521
|
+
for await (const value of prefetcher) {
|
|
522
|
+
loopCount++;
|
|
523
|
+
iteratedValues.push(value);
|
|
743
524
|
}
|
|
744
|
-
})
|
|
745
|
-
|
|
525
|
+
}).rejects.toThrowError('throwing on index 0');
|
|
526
|
+
await sleep(500);
|
|
746
527
|
expect(loopCount).toBe(0);
|
|
747
528
|
expect(mappedValues).toEqual([]);
|
|
748
529
|
expect(iteratedValues).toEqual([]);
|
|
749
|
-
})
|
|
530
|
+
});
|
|
750
531
|
// The 2nd iterable item throwing is distinct from the 1st when concurrency is 1 because
|
|
751
532
|
// it means that the sourceNext() is invoked from next() or sourceNext() and not from
|
|
752
533
|
// the constructor
|
|
753
|
-
it('catches exception from source iterator - 2nd item', () =>
|
|
534
|
+
it('catches exception from source iterator - 2nd item', async () => {
|
|
754
535
|
const input = new ThrowingIterator(100, 1, 100);
|
|
755
536
|
const mappedValues = [];
|
|
756
537
|
const iteratedValues = [];
|
|
757
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
538
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
758
539
|
mappedValues.push(value);
|
|
759
|
-
|
|
540
|
+
await sleep(100);
|
|
760
541
|
return value;
|
|
761
|
-
}
|
|
542
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
762
543
|
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; }
|
|
544
|
+
await expect(async () => {
|
|
545
|
+
for await (const value of prefetcher) {
|
|
546
|
+
loopCount++;
|
|
547
|
+
iteratedValues.push(value);
|
|
780
548
|
}
|
|
781
|
-
})
|
|
782
|
-
|
|
549
|
+
}).rejects.toThrowError('throwing on index 1');
|
|
550
|
+
await sleep(500);
|
|
783
551
|
expect(loopCount).toBe(1);
|
|
784
552
|
expect(mappedValues).toEqual([0]);
|
|
785
553
|
expect(iteratedValues).toEqual([0]);
|
|
786
|
-
})
|
|
554
|
+
});
|
|
787
555
|
});
|
|
788
556
|
describe('concurrency 2, maxUnread 4', () => {
|
|
789
557
|
const concurrency = 2;
|
|
790
558
|
const maxUnread = 4;
|
|
791
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
792
|
-
const input = [1, () =>
|
|
559
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
560
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
793
561
|
const mappedValues = [];
|
|
794
562
|
const iteratedValues = [];
|
|
795
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
796
|
-
value = typeof value === 'function' ?
|
|
563
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
564
|
+
value = typeof value === 'function' ? await value() : value;
|
|
797
565
|
mappedValues.push(value);
|
|
798
566
|
if (value === 1) {
|
|
799
|
-
|
|
567
|
+
await sleep(100);
|
|
800
568
|
throw new Error('throw on 1st');
|
|
801
569
|
}
|
|
802
570
|
return value;
|
|
803
|
-
}
|
|
571
|
+
}, { concurrency, maxUnread });
|
|
804
572
|
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; }
|
|
573
|
+
await expect(async () => {
|
|
574
|
+
for await (const value of prefetcher) {
|
|
575
|
+
loopCount++;
|
|
576
|
+
iteratedValues.push(value);
|
|
822
577
|
}
|
|
823
|
-
})
|
|
824
|
-
|
|
578
|
+
}).rejects.toThrowError('throw on 1st');
|
|
579
|
+
await sleep(500);
|
|
825
580
|
expect(loopCount).toBe(0);
|
|
826
581
|
expect(mappedValues).toEqual([1, 2]);
|
|
827
582
|
expect(iteratedValues).toEqual([]);
|
|
828
|
-
})
|
|
829
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
830
|
-
const input = [1, () =>
|
|
583
|
+
});
|
|
584
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
585
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
831
586
|
const mappedValues = [];
|
|
832
587
|
const iteratedValues = [];
|
|
833
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
834
|
-
value = typeof value === 'function' ?
|
|
588
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
589
|
+
value = typeof value === 'function' ? await value() : value;
|
|
835
590
|
mappedValues.push(value);
|
|
836
591
|
if (value === 2) {
|
|
837
592
|
throw new Error('throw on 2nd');
|
|
838
593
|
}
|
|
839
|
-
|
|
594
|
+
await sleep(100);
|
|
840
595
|
return value;
|
|
841
|
-
}
|
|
596
|
+
}, { concurrency, maxUnread });
|
|
842
597
|
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; }
|
|
598
|
+
await expect(async () => {
|
|
599
|
+
for await (const value of prefetcher) {
|
|
600
|
+
loopCount++;
|
|
601
|
+
iteratedValues.push(value);
|
|
860
602
|
}
|
|
861
|
-
})
|
|
862
|
-
|
|
603
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
604
|
+
await sleep(300);
|
|
863
605
|
expect(loopCount).toBe(2);
|
|
864
606
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
865
607
|
expect(iteratedValues).toEqual([1, 3]);
|
|
866
|
-
})
|
|
867
|
-
it('catches exception from mapper - 1st item - stopOnMapperError false', () =>
|
|
868
|
-
const input = [1, () =>
|
|
608
|
+
});
|
|
609
|
+
it('catches exception from mapper - 1st item - stopOnMapperError false', async () => {
|
|
610
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
869
611
|
const mappedValues = [];
|
|
870
612
|
const iteratedValues = [];
|
|
871
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
872
|
-
value = typeof value === 'function' ?
|
|
613
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
614
|
+
value = typeof value === 'function' ? await value() : value;
|
|
873
615
|
mappedValues.push(value);
|
|
874
616
|
if (value === 1) {
|
|
875
617
|
throw new Error('throw on 1st');
|
|
876
618
|
}
|
|
877
|
-
|
|
619
|
+
await sleep(100);
|
|
878
620
|
return value;
|
|
879
|
-
}
|
|
621
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
880
622
|
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; }
|
|
623
|
+
await expect(async () => {
|
|
624
|
+
for await (const value of prefetcher) {
|
|
625
|
+
loopCount++;
|
|
626
|
+
iteratedValues.push(value);
|
|
898
627
|
}
|
|
899
|
-
})
|
|
900
|
-
|
|
628
|
+
}).rejects.toThrowError('throw on 1st');
|
|
629
|
+
await sleep(300);
|
|
901
630
|
expect(loopCount).toBe(2);
|
|
902
631
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
903
632
|
expect(iteratedValues).toEqual([3, 2]);
|
|
904
|
-
})
|
|
905
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError false', () =>
|
|
906
|
-
const input = [1, () =>
|
|
633
|
+
});
|
|
634
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError false', async () => {
|
|
635
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
907
636
|
const mappedValues = [];
|
|
908
637
|
const iteratedValues = [];
|
|
909
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
910
|
-
value = typeof value === 'function' ?
|
|
638
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
639
|
+
value = typeof value === 'function' ? await value() : value;
|
|
911
640
|
mappedValues.push(value);
|
|
912
641
|
if (value === 2) {
|
|
913
642
|
throw new Error('throw on 2nd');
|
|
914
643
|
}
|
|
915
|
-
|
|
644
|
+
await sleep(100);
|
|
916
645
|
return value;
|
|
917
|
-
}
|
|
646
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
918
647
|
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; }
|
|
648
|
+
await expect(async () => {
|
|
649
|
+
for await (const value of prefetcher) {
|
|
650
|
+
loopCount++;
|
|
651
|
+
iteratedValues.push(value);
|
|
936
652
|
}
|
|
937
|
-
})
|
|
938
|
-
|
|
653
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
654
|
+
await sleep(300);
|
|
939
655
|
expect(loopCount).toBe(2);
|
|
940
656
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
941
657
|
expect(iteratedValues).toEqual([1, 3]);
|
|
942
|
-
})
|
|
943
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
658
|
+
});
|
|
659
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
944
660
|
const input = new SleepIterator(10);
|
|
945
661
|
const mappedValues = [];
|
|
946
662
|
const iteratedValues = [];
|
|
@@ -949,30 +665,17 @@ describe('IterableMapper', () => {
|
|
|
949
665
|
throw new Error('throw on each');
|
|
950
666
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
951
667
|
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; }
|
|
668
|
+
await expect(async () => {
|
|
669
|
+
for await (const value of prefetcher) {
|
|
670
|
+
loopCount++;
|
|
671
|
+
iteratedValues.push(value);
|
|
969
672
|
}
|
|
970
|
-
})
|
|
673
|
+
}).rejects.toThrowError('throw on each');
|
|
971
674
|
expect(loopCount).toBe(0);
|
|
972
675
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
973
676
|
expect(iteratedValues).toEqual([]);
|
|
974
|
-
})
|
|
975
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
677
|
+
});
|
|
678
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
976
679
|
const input = new SleepIterator(10);
|
|
977
680
|
const mappedValues = [];
|
|
978
681
|
const iteratedValues = [];
|
|
@@ -981,138 +684,86 @@ describe('IterableMapper', () => {
|
|
|
981
684
|
throw new Error('throw on each');
|
|
982
685
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
983
686
|
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; }
|
|
687
|
+
await expect(async () => {
|
|
688
|
+
for await (const value of prefetcher) {
|
|
689
|
+
loopCount++;
|
|
690
|
+
iteratedValues.push(value);
|
|
1001
691
|
}
|
|
1002
|
-
})
|
|
692
|
+
}).rejects.toThrowError('throw on each');
|
|
1003
693
|
expect(loopCount).toBe(0);
|
|
1004
694
|
expect(mappedValues).toEqual([1]);
|
|
1005
695
|
expect(iteratedValues).toEqual([]);
|
|
1006
|
-
})
|
|
1007
|
-
it('catches exception from source iterator - 1st item', () =>
|
|
696
|
+
});
|
|
697
|
+
it('catches exception from source iterator - 1st item', async () => {
|
|
1008
698
|
const input = new ThrowingIterator(100, 0, 100);
|
|
1009
699
|
const mappedValues = [];
|
|
1010
700
|
const iteratedValues = [];
|
|
1011
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
701
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
1012
702
|
mappedValues.push(value);
|
|
1013
|
-
|
|
703
|
+
await sleep(100);
|
|
1014
704
|
return value;
|
|
1015
|
-
}
|
|
705
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1016
706
|
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; }
|
|
707
|
+
await expect(async () => {
|
|
708
|
+
for await (const value of prefetcher) {
|
|
709
|
+
loopCount++;
|
|
710
|
+
iteratedValues.push(value);
|
|
1034
711
|
}
|
|
1035
|
-
})
|
|
1036
|
-
|
|
712
|
+
}).rejects.toThrowError('throwing on index 0');
|
|
713
|
+
await sleep(500);
|
|
1037
714
|
expect(loopCount).toBe(0);
|
|
1038
715
|
expect(mappedValues).toEqual([]);
|
|
1039
716
|
expect(iteratedValues).toEqual([]);
|
|
1040
|
-
})
|
|
717
|
+
});
|
|
1041
718
|
// The 2nd iterable item throwing is distinct from the 1st when concurrency is 1 because
|
|
1042
719
|
// it means that the sourceNext() is invoked from next() or sourceNext() and not from
|
|
1043
720
|
// the constructor
|
|
1044
|
-
it('catches exception from source iterator - 2nd item', () =>
|
|
721
|
+
it('catches exception from source iterator - 2nd item', async () => {
|
|
1045
722
|
const input = new ThrowingIterator(100, 1, 100);
|
|
1046
723
|
const mappedValues = [];
|
|
1047
724
|
const iteratedValues = [];
|
|
1048
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
725
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
1049
726
|
mappedValues.push(value);
|
|
1050
|
-
|
|
727
|
+
await sleep(100);
|
|
1051
728
|
return value;
|
|
1052
|
-
}
|
|
729
|
+
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1053
730
|
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; }
|
|
731
|
+
await expect(async () => {
|
|
732
|
+
for await (const value of prefetcher) {
|
|
733
|
+
loopCount++;
|
|
734
|
+
iteratedValues.push(value);
|
|
1071
735
|
}
|
|
1072
|
-
})
|
|
1073
|
-
|
|
736
|
+
}).rejects.toThrowError('throwing on index 1');
|
|
737
|
+
await sleep(500);
|
|
1074
738
|
expect(loopCount).toBe(1);
|
|
1075
739
|
expect(mappedValues).toEqual([0]);
|
|
1076
740
|
expect(iteratedValues).toEqual([0]);
|
|
1077
|
-
})
|
|
741
|
+
});
|
|
1078
742
|
});
|
|
1079
743
|
describe('concurrency Number.POSITIVE_INFINITY, maxUnread Number.POSITIVE_INFINITY', () => {
|
|
1080
744
|
const concurrency = Number.POSITIVE_INFINITY;
|
|
1081
745
|
const maxUnread = Number.POSITIVE_INFINITY;
|
|
1082
|
-
it('catches exception from mapper - 1st item - stopOnMapperError true', () =>
|
|
1083
|
-
const input = [1, () =>
|
|
746
|
+
it('catches exception from mapper - 1st item - stopOnMapperError true', async () => {
|
|
747
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
1084
748
|
const mappedValues = [];
|
|
1085
749
|
const iteratedValues = [];
|
|
1086
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
1087
|
-
value = typeof value === 'function' ?
|
|
750
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
751
|
+
value = typeof value === 'function' ? await value() : value;
|
|
1088
752
|
mappedValues.push(value);
|
|
1089
753
|
if (value === 1) {
|
|
1090
|
-
|
|
754
|
+
await sleep(100);
|
|
1091
755
|
throw new Error('throw on 1st');
|
|
1092
756
|
}
|
|
1093
757
|
return value;
|
|
1094
|
-
}
|
|
758
|
+
}, { concurrency, maxUnread });
|
|
1095
759
|
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; }
|
|
760
|
+
await expect(async () => {
|
|
761
|
+
for await (const value of prefetcher) {
|
|
762
|
+
loopCount++;
|
|
763
|
+
iteratedValues.push(value);
|
|
1113
764
|
}
|
|
1114
|
-
})
|
|
1115
|
-
|
|
765
|
+
}).rejects.toThrowError('throw on 1st');
|
|
766
|
+
await sleep(500);
|
|
1116
767
|
expect(loopCount).toBe(1);
|
|
1117
768
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
1118
769
|
// NOTE: This seems wrong - Item 2 succeeds at being mapped, but after the 1st item throws.
|
|
@@ -1126,83 +777,57 @@ describe('IterableMapper', () => {
|
|
|
1126
777
|
// then this behavior would match their results exactly (the 1st item would cause the iteration
|
|
1127
778
|
// loop to break out).
|
|
1128
779
|
expect(iteratedValues).toEqual([3]);
|
|
1129
|
-
})
|
|
1130
|
-
it('catches exception from mapper - 2nd item - stopOnMapperError true', () =>
|
|
1131
|
-
const input = [1, () =>
|
|
780
|
+
});
|
|
781
|
+
it('catches exception from mapper - 2nd item - stopOnMapperError true', async () => {
|
|
782
|
+
const input = [1, async () => sleep(300, 2), 3];
|
|
1132
783
|
const mappedValues = [];
|
|
1133
784
|
const iteratedValues = [];
|
|
1134
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(input, (value) =>
|
|
1135
|
-
value = typeof value === 'function' ?
|
|
785
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(input, async (value) => {
|
|
786
|
+
value = typeof value === 'function' ? await value() : value;
|
|
1136
787
|
mappedValues.push(value);
|
|
1137
788
|
if (value === 2) {
|
|
1138
789
|
throw new Error('throw on 2nd');
|
|
1139
790
|
}
|
|
1140
|
-
|
|
791
|
+
await sleep(100);
|
|
1141
792
|
return value;
|
|
1142
|
-
}
|
|
793
|
+
}, { concurrency, maxUnread });
|
|
1143
794
|
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; }
|
|
795
|
+
await expect(async () => {
|
|
796
|
+
for await (const value of prefetcher) {
|
|
797
|
+
loopCount++;
|
|
798
|
+
iteratedValues.push(value);
|
|
1161
799
|
}
|
|
1162
|
-
})
|
|
1163
|
-
|
|
800
|
+
}).rejects.toThrowError('throw on 2nd');
|
|
801
|
+
await sleep(300);
|
|
1164
802
|
expect(loopCount).toBe(2);
|
|
1165
803
|
expect(mappedValues).toEqual([1, 3, 2]);
|
|
1166
804
|
expect(iteratedValues).toEqual([1, 3]);
|
|
1167
|
-
})
|
|
1168
|
-
it('async mapper works', () =>
|
|
1169
|
-
var _j, e_28, _k, _l;
|
|
805
|
+
});
|
|
806
|
+
it('async mapper works', async () => {
|
|
1170
807
|
const max = 100;
|
|
1171
808
|
const iterator = new SleepIterator(max);
|
|
1172
809
|
let total = 0;
|
|
1173
810
|
let callCount = 0;
|
|
1174
|
-
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, (value) =>
|
|
811
|
+
const prefetcher = new iterable_mapper_1.IterableMapper(iterator, async (value) => {
|
|
1175
812
|
callCount++;
|
|
1176
813
|
total += value;
|
|
1177
|
-
|
|
814
|
+
await sleep(10 * (callCount % 6));
|
|
1178
815
|
return total;
|
|
1179
|
-
}
|
|
816
|
+
}, { concurrency, maxUnread });
|
|
1180
817
|
let lastTotal = 0;
|
|
1181
818
|
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);
|
|
819
|
+
for await (const item of prefetcher) {
|
|
820
|
+
loopCount++;
|
|
821
|
+
if (item > lastTotal) {
|
|
822
|
+
lastTotal = item;
|
|
1197
823
|
}
|
|
1198
|
-
finally { if (e_28) throw e_28.error; }
|
|
1199
824
|
}
|
|
1200
825
|
expect(callCount).toBe(max);
|
|
1201
826
|
expect(loopCount).toBe(max);
|
|
1202
827
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
1203
828
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
1204
|
-
})
|
|
1205
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', () =>
|
|
829
|
+
});
|
|
830
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError true', async () => {
|
|
1206
831
|
const input = new SleepIterator(10);
|
|
1207
832
|
const mappedValues = [];
|
|
1208
833
|
const iteratedValues = [];
|
|
@@ -1211,30 +836,17 @@ describe('IterableMapper', () => {
|
|
|
1211
836
|
throw new Error('throw on each');
|
|
1212
837
|
}, { concurrency, maxUnread, stopOnMapperError: true });
|
|
1213
838
|
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; }
|
|
839
|
+
await expect(async () => {
|
|
840
|
+
for await (const value of prefetcher) {
|
|
841
|
+
loopCount++;
|
|
842
|
+
iteratedValues.push(value);
|
|
1231
843
|
}
|
|
1232
|
-
})
|
|
844
|
+
}).rejects.toThrowError('throw on each');
|
|
1233
845
|
expect(loopCount).toBe(0);
|
|
1234
846
|
expect(mappedValues).toEqual([1]);
|
|
1235
847
|
expect(iteratedValues).toEqual([]);
|
|
1236
|
-
})
|
|
1237
|
-
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', () =>
|
|
848
|
+
});
|
|
849
|
+
it('catches exception from mapper - 10 of 10 items - stopOnMapperError false', async () => {
|
|
1238
850
|
const input = new SleepIterator(10);
|
|
1239
851
|
const mappedValues = [];
|
|
1240
852
|
const iteratedValues = [];
|
|
@@ -1243,29 +855,16 @@ describe('IterableMapper', () => {
|
|
|
1243
855
|
throw new Error('throw on each');
|
|
1244
856
|
}, { concurrency, maxUnread, stopOnMapperError: false });
|
|
1245
857
|
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; }
|
|
858
|
+
await expect(async () => {
|
|
859
|
+
for await (const value of prefetcher) {
|
|
860
|
+
loopCount++;
|
|
861
|
+
iteratedValues.push(value);
|
|
1263
862
|
}
|
|
1264
|
-
})
|
|
863
|
+
}).rejects.toThrowError('throw on each');
|
|
1265
864
|
expect(loopCount).toBe(0);
|
|
1266
865
|
expect(mappedValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
1267
866
|
expect(iteratedValues).toEqual([]);
|
|
1268
|
-
})
|
|
867
|
+
});
|
|
1269
868
|
});
|
|
1270
869
|
});
|
|
1271
870
|
//# sourceMappingURL=iterable-mapper.test.js.map
|