@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-queue-mapper-simple.test.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper-simple.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iterable-queue-mapper-simple.test.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper-simple.test.ts"],"names":[],"mappings":";;AAAA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CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE3C,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,sBAAsB,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC;QAC3E,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG,eAAe,CAAC,CAAC;QAEnE,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,77 +1,57 @@
|
|
|
1
|
-
import { Mapper } from './iterable-mapper';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Must be an integer from 1 and up or `Infinity`, must be <= `maxUnread`.
|
|
7
|
-
*
|
|
8
|
-
* @default 4
|
|
9
|
-
*/
|
|
10
|
-
readonly concurrency?: number;
|
|
11
|
-
/**
|
|
12
|
-
* Number of pending unread iterable items.
|
|
13
|
-
*
|
|
14
|
-
* Must be an integer from 1 and up or `Infinity`, must be >= `concurrency`.
|
|
15
|
-
*
|
|
16
|
-
* @default 8
|
|
17
|
-
*/
|
|
18
|
-
readonly maxUnread?: number;
|
|
19
|
-
/**
|
|
20
|
-
* When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
|
|
21
|
-
*
|
|
22
|
-
* @default true
|
|
23
|
-
*/
|
|
24
|
-
readonly stopOnMapperError?: boolean;
|
|
25
|
-
}
|
|
1
|
+
import { IterableMapperOptions, Mapper } from './iterable-mapper';
|
|
2
|
+
/**
|
|
3
|
+
* Options for IterableQueueMapper
|
|
4
|
+
*/
|
|
5
|
+
export type IterableQueueMapperOptions = IterableMapperOptions;
|
|
26
6
|
/**
|
|
27
7
|
* Accepts queue items via `enqueue` and calls the `mapper` on them
|
|
28
|
-
* with specified concurrency
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
* the queue is full, until an item is read.
|
|
8
|
+
* with specified `concurrency`, storing the `mapper` result in a queue
|
|
9
|
+
* of `maxUnread` size, before being iterated / read by the caller.
|
|
10
|
+
* The `enqueue` method will block if the queue is full, until an item is read.
|
|
32
11
|
*
|
|
33
12
|
* @remarks
|
|
34
13
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
14
|
+
* ### Typical Use Case
|
|
15
|
+
* - Pushing items to an async I/O destination
|
|
16
|
+
* - In the simple sequential (`concurrency: 1`) case, allows 1 item to be flushed async while caller prepares next item
|
|
17
|
+
* - Results of the flushed items are needed in a subsequent step (if they are not, use `IterableQueueMapperSimple`)
|
|
18
|
+
* - Prevents the producer from racing ahead of the consumer if `maxUnread` is reached
|
|
19
|
+
*
|
|
20
|
+
* ### Error Handling
|
|
21
|
+
* The mapper should ideally handle all errors internally to enable error handling
|
|
22
|
+
* closest to where they occur. However, if errors do escape the mapper:
|
|
38
23
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* `mapper` function of the `IterableMapper`.
|
|
24
|
+
* When `stopOnMapperError` is true (default):
|
|
25
|
+
* - First error immediately stops processing
|
|
26
|
+
* - Error is thrown from the `AsyncIterator`'s next() call
|
|
43
27
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
28
|
+
* When `stopOnMapperError` is false:
|
|
29
|
+
* - Processing continues despite errors
|
|
30
|
+
* - All errors are collected and thrown together
|
|
31
|
+
* - Errors are thrown as `AggregateError` after all items complete
|
|
32
|
+
*
|
|
33
|
+
* ### Usage
|
|
34
|
+
* - Items are added to the queue via the `await enqueue()` method
|
|
35
|
+
* - IMPORTANT: `await enqueue()` method will block until a slot is available, if queue is full
|
|
36
|
+
* - Call `done()` when no more items will be enqueued
|
|
37
|
+
* - IMPORTANT: Always `await onIdle()` to ensure all items are processed
|
|
50
38
|
*
|
|
51
39
|
* @category Enqueue Input
|
|
40
|
+
*
|
|
41
|
+
* @see {@link IterableMapper} for underlying mapper implementation and examples of combined usage
|
|
52
42
|
*/
|
|
53
43
|
export declare class IterableQueueMapper<Element, NewElement> implements AsyncIterable<NewElement> {
|
|
54
44
|
private _iterableMapper;
|
|
55
45
|
private _sourceIterable;
|
|
56
46
|
/**
|
|
57
|
-
* Create a new `IterableQueueMapper`
|
|
58
|
-
*
|
|
59
|
-
* @param mapper Function which is called for every item in `input`.
|
|
60
|
-
* Expected to return a `Promise` or value.
|
|
47
|
+
* Create a new `IterableQueueMapper`, which uses `IterableMapper` underneath, and exposes a
|
|
48
|
+
* queue interface for adding items that are not exposed via an iterator.
|
|
61
49
|
*
|
|
62
|
-
*
|
|
63
|
-
* out of the `mapper` function as this enables the best handling of errors
|
|
64
|
-
* closest to the time that they occur.
|
|
65
|
-
*
|
|
66
|
-
* If the `mapper` function does allow an error to be thrown then the
|
|
67
|
-
* `stopOnMapperError` option controls the behavior:
|
|
68
|
-
* - `stopOnMapperError`: `true` - will throw the error
|
|
69
|
-
* out of `next` or the `AsyncIterator` returned from `[Symbol.asyncIterator]`
|
|
70
|
-
* and stop processing.
|
|
71
|
-
* - `stopOnMapperError`: `false` - will continue processing
|
|
72
|
-
* and accumulate the errors to be thrown from `next` or the `AsyncIterator`
|
|
73
|
-
* returned from `[Symbol.asyncIterator]` when all items have been processed.
|
|
50
|
+
* @param mapper Function called for every enqueued item. Returns a `Promise` or value.
|
|
74
51
|
* @param options IterableQueueMapper options
|
|
52
|
+
*
|
|
53
|
+
* @see {@link IterableQueueMapper} for full class documentation
|
|
54
|
+
* @see {@link IterableMapper} for underlying mapper implementation and examples of combined usage
|
|
75
55
|
*/
|
|
76
56
|
constructor(mapper: Mapper<Element, NewElement>, options?: IterableQueueMapperOptions);
|
|
77
57
|
[Symbol.asyncIterator](): AsyncIterator<NewElement>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-queue-mapper.d.ts","sourceRoot":"","sources":["../../src/iterable-queue-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"iterable-queue-mapper.d.ts","sourceRoot":"","sources":["../../src/iterable-queue-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGlF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAE,YAAW,aAAa,CAAC,UAAU,CAAC;IACxF,OAAO,CAAC,eAAe,CAAsC;IAE7D,OAAO,CAAC,eAAe,CAAyB;IAEhD;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,GAAE,0BAA+B;IAOlF,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC;IAI1D;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAIxD;;;;OAIG;IACU,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;;OAIG;IACI,IAAI,IAAI,IAAI;CAGpB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IterableQueueMapper = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
//
|
|
6
5
|
// 2021-08-25 - Initially based on: https://raw.githubusercontent.com/sindresorhus/p-map/main/index.js
|
|
7
6
|
//
|
|
@@ -9,51 +8,51 @@ const iterable_mapper_1 = require("./iterable-mapper");
|
|
|
9
8
|
const iterable_queue_1 = require("./iterable-queue");
|
|
10
9
|
/**
|
|
11
10
|
* Accepts queue items via `enqueue` and calls the `mapper` on them
|
|
12
|
-
* with specified concurrency
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
-
* the queue is full, until an item is read.
|
|
11
|
+
* with specified `concurrency`, storing the `mapper` result in a queue
|
|
12
|
+
* of `maxUnread` size, before being iterated / read by the caller.
|
|
13
|
+
* The `enqueue` method will block if the queue is full, until an item is read.
|
|
16
14
|
*
|
|
17
15
|
* @remarks
|
|
18
16
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* ### Typical Use Case
|
|
18
|
+
* - Pushing items to an async I/O destination
|
|
19
|
+
* - In the simple sequential (`concurrency: 1`) case, allows 1 item to be flushed async while caller prepares next item
|
|
20
|
+
* - Results of the flushed items are needed in a subsequent step (if they are not, use `IterableQueueMapperSimple`)
|
|
21
|
+
* - Prevents the producer from racing ahead of the consumer if `maxUnread` is reached
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `mapper` function of the `IterableMapper`.
|
|
23
|
+
* ### Error Handling
|
|
24
|
+
* The mapper should ideally handle all errors internally to enable error handling
|
|
25
|
+
* closest to where they occur. However, if errors do escape the mapper:
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* `
|
|
33
|
-
*
|
|
27
|
+
* When `stopOnMapperError` is true (default):
|
|
28
|
+
* - First error immediately stops processing
|
|
29
|
+
* - Error is thrown from the `AsyncIterator`'s next() call
|
|
30
|
+
*
|
|
31
|
+
* When `stopOnMapperError` is false:
|
|
32
|
+
* - Processing continues despite errors
|
|
33
|
+
* - All errors are collected and thrown together
|
|
34
|
+
* - Errors are thrown as `AggregateError` after all items complete
|
|
35
|
+
*
|
|
36
|
+
* ### Usage
|
|
37
|
+
* - Items are added to the queue via the `await enqueue()` method
|
|
38
|
+
* - IMPORTANT: `await enqueue()` method will block until a slot is available, if queue is full
|
|
39
|
+
* - Call `done()` when no more items will be enqueued
|
|
40
|
+
* - IMPORTANT: Always `await onIdle()` to ensure all items are processed
|
|
34
41
|
*
|
|
35
42
|
* @category Enqueue Input
|
|
43
|
+
*
|
|
44
|
+
* @see {@link IterableMapper} for underlying mapper implementation and examples of combined usage
|
|
36
45
|
*/
|
|
37
46
|
class IterableQueueMapper {
|
|
38
47
|
/**
|
|
39
|
-
* Create a new `IterableQueueMapper`
|
|
40
|
-
*
|
|
41
|
-
* @param mapper Function which is called for every item in `input`.
|
|
42
|
-
* Expected to return a `Promise` or value.
|
|
48
|
+
* Create a new `IterableQueueMapper`, which uses `IterableMapper` underneath, and exposes a
|
|
49
|
+
* queue interface for adding items that are not exposed via an iterator.
|
|
43
50
|
*
|
|
44
|
-
*
|
|
45
|
-
* out of the `mapper` function as this enables the best handling of errors
|
|
46
|
-
* closest to the time that they occur.
|
|
47
|
-
*
|
|
48
|
-
* If the `mapper` function does allow an error to be thrown then the
|
|
49
|
-
* `stopOnMapperError` option controls the behavior:
|
|
50
|
-
* - `stopOnMapperError`: `true` - will throw the error
|
|
51
|
-
* out of `next` or the `AsyncIterator` returned from `[Symbol.asyncIterator]`
|
|
52
|
-
* and stop processing.
|
|
53
|
-
* - `stopOnMapperError`: `false` - will continue processing
|
|
54
|
-
* and accumulate the errors to be thrown from `next` or the `AsyncIterator`
|
|
55
|
-
* returned from `[Symbol.asyncIterator]` when all items have been processed.
|
|
51
|
+
* @param mapper Function called for every enqueued item. Returns a `Promise` or value.
|
|
56
52
|
* @param options IterableQueueMapper options
|
|
53
|
+
*
|
|
54
|
+
* @see {@link IterableQueueMapper} for full class documentation
|
|
55
|
+
* @see {@link IterableMapper} for underlying mapper implementation and examples of combined usage
|
|
57
56
|
*/
|
|
58
57
|
constructor(mapper, options = {}) {
|
|
59
58
|
this._sourceIterable = new iterable_queue_1.IterableQueue({
|
|
@@ -69,20 +68,16 @@ class IterableQueueMapper {
|
|
|
69
68
|
* Called every time an item is needed
|
|
70
69
|
* @returns Iterator result
|
|
71
70
|
*/
|
|
72
|
-
next() {
|
|
73
|
-
return
|
|
74
|
-
return this._iterableMapper.next();
|
|
75
|
-
});
|
|
71
|
+
async next() {
|
|
72
|
+
return this._iterableMapper.next();
|
|
76
73
|
}
|
|
77
74
|
/**
|
|
78
75
|
* Add an item to the queue, wait if the queue is full.
|
|
79
76
|
*
|
|
80
77
|
* @param item Element to add
|
|
81
78
|
*/
|
|
82
|
-
enqueue(item) {
|
|
83
|
-
|
|
84
|
-
yield this._sourceIterable.enqueue(item);
|
|
85
|
-
});
|
|
79
|
+
async enqueue(item) {
|
|
80
|
+
await this._sourceIterable.enqueue(item);
|
|
86
81
|
}
|
|
87
82
|
/**
|
|
88
83
|
* Indicate that no more items will be enqueued.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-queue-mapper.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iterable-queue-mapper.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper.ts"],"names":[],"mappings":";;;AAAA,EAAE;AACF,sGAAsG;AACtG,EAAE;AACF,uDAAkF;AAClF,qDAAiD;AAOjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,mBAAmB;IAK9B;;;;;;;;;OASG;IACH,YAAY,MAAmC,EAAE,UAAsC,EAAE;QACvF,IAAI,CAAC,eAAe,GAAG,IAAI,8BAAa,CAAC;YACvC,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;QACH,IAAI,CAAC,eAAe,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,CAAC;IAEM,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI;QACf,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAAC,IAAa;QAChC,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACI,IAAI;QACT,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF;AApDD,kDAoDC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
/// <reference types="jest" />
|
|
5
4
|
const iterable_queue_mapper_1 = require("./iterable-queue-mapper");
|
|
6
5
|
const util_1 = require("util");
|
|
7
6
|
const sleep = (0, util_1.promisify)(setTimeout);
|
|
8
|
-
function mapper({ value, ms }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return value;
|
|
12
|
-
});
|
|
7
|
+
async function mapper({ value, ms }) {
|
|
8
|
+
await sleep(ms);
|
|
9
|
+
return value;
|
|
13
10
|
}
|
|
14
11
|
describe('IterableQueueMapper', () => {
|
|
15
12
|
beforeAll(() => {
|
|
@@ -19,8 +16,7 @@ describe('IterableQueueMapper', () => {
|
|
|
19
16
|
jest.clearAllMocks();
|
|
20
17
|
});
|
|
21
18
|
describe('simple tests', () => {
|
|
22
|
-
it('simple mapper works - sync mapper', () =>
|
|
23
|
-
var _a, e_1, _b, _c;
|
|
19
|
+
it('simple mapper works - sync mapper', async () => {
|
|
24
20
|
const max = 100;
|
|
25
21
|
let total = 0;
|
|
26
22
|
let callCount = 0;
|
|
@@ -30,40 +26,27 @@ describe('IterableQueueMapper', () => {
|
|
|
30
26
|
return total;
|
|
31
27
|
});
|
|
32
28
|
// Enqueue items in the background
|
|
33
|
-
void (() =>
|
|
29
|
+
void (async () => {
|
|
34
30
|
for (let i = 0; i < max; i++) {
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
await sleep(1 * (i % 10));
|
|
32
|
+
await prefetcher.enqueue(i + 1);
|
|
37
33
|
}
|
|
38
34
|
prefetcher.done();
|
|
39
|
-
})
|
|
35
|
+
})();
|
|
40
36
|
let lastTotal = 0;
|
|
41
37
|
let loopCount = 0;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const item = _c;
|
|
47
|
-
loopCount++;
|
|
48
|
-
if (item > lastTotal) {
|
|
49
|
-
lastTotal = item;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
54
|
-
finally {
|
|
55
|
-
try {
|
|
56
|
-
if (!_d && !_a && (_b = prefetcher_1.return)) yield _b.call(prefetcher_1);
|
|
38
|
+
for await (const item of prefetcher) {
|
|
39
|
+
loopCount++;
|
|
40
|
+
if (item > lastTotal) {
|
|
41
|
+
lastTotal = item;
|
|
57
42
|
}
|
|
58
|
-
finally { if (e_1) throw e_1.error; }
|
|
59
43
|
}
|
|
60
44
|
expect(callCount).toBe(max);
|
|
61
45
|
expect(loopCount).toBe(max);
|
|
62
46
|
expect(total).toBe((max * (max + 1)) / 2);
|
|
63
47
|
expect(lastTotal).toBe((max * (max + 1)) / 2);
|
|
64
|
-
})
|
|
65
|
-
it('right number run in parallel - simple', () =>
|
|
66
|
-
var _e, e_2, _f, _g;
|
|
48
|
+
});
|
|
49
|
+
it('right number run in parallel - simple', async () => {
|
|
67
50
|
const startTime = Date.now();
|
|
68
51
|
const max = 8;
|
|
69
52
|
const delayBetweenMs = 200;
|
|
@@ -79,81 +62,58 @@ describe('IterableQueueMapper', () => {
|
|
|
79
62
|
];
|
|
80
63
|
const prefetcher = new iterable_queue_mapper_1.IterableQueueMapper(mapper, { concurrency: 2, maxUnread: 4 });
|
|
81
64
|
// Enqueue items in the background
|
|
82
|
-
void (() =>
|
|
65
|
+
void (async () => {
|
|
83
66
|
for (const item of input) {
|
|
84
|
-
|
|
67
|
+
await prefetcher.enqueue(item);
|
|
85
68
|
}
|
|
86
69
|
prefetcher.done();
|
|
87
|
-
})
|
|
70
|
+
})();
|
|
88
71
|
let lastTotal = 0;
|
|
89
72
|
let loopCount = 0;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const item = _g;
|
|
95
|
-
loopCount++;
|
|
96
|
-
if (item > lastTotal) {
|
|
97
|
-
lastTotal = item;
|
|
98
|
-
}
|
|
73
|
+
for await (const item of prefetcher) {
|
|
74
|
+
loopCount++;
|
|
75
|
+
if (item > lastTotal) {
|
|
76
|
+
lastTotal = item;
|
|
99
77
|
}
|
|
100
78
|
}
|
|
101
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
102
|
-
finally {
|
|
103
|
-
try {
|
|
104
|
-
if (!_h && !_e && (_f = prefetcher_2.return)) yield _f.call(prefetcher_2);
|
|
105
|
-
}
|
|
106
|
-
finally { if (e_2) throw e_2.error; }
|
|
107
|
-
}
|
|
108
79
|
expect(loopCount).toBe(max);
|
|
109
80
|
expect(lastTotal).toBe(max);
|
|
110
81
|
// Should require at least 4 batches
|
|
82
|
+
const duration = Date.now() - startTime;
|
|
111
83
|
expect(Date.now() - startTime).toBeLessThan(5 * delayBetweenMs);
|
|
112
|
-
expect(
|
|
113
|
-
})
|
|
114
|
-
it('right number run in parallel - complex', () =>
|
|
115
|
-
var _j, e_3, _k, _l;
|
|
84
|
+
expect(Math.ceil(duration)).toBeGreaterThan(4 * delayBetweenMs);
|
|
85
|
+
});
|
|
86
|
+
it('right number run in parallel - complex', async () => {
|
|
116
87
|
const prefetcher = new iterable_queue_mapper_1.IterableQueueMapper(mapper, { concurrency: 4, maxUnread: 4 });
|
|
117
88
|
const delayBetweenMs = 500;
|
|
118
89
|
// First 4 added should not wait at all
|
|
119
90
|
const startTime = Date.now();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
91
|
+
await prefetcher.enqueue({ value: 1, ms: delayBetweenMs });
|
|
92
|
+
await prefetcher.enqueue({ value: 2, ms: delayBetweenMs });
|
|
93
|
+
await prefetcher.enqueue({ value: 3, ms: delayBetweenMs });
|
|
94
|
+
await prefetcher.enqueue({ value: 4, ms: delayBetweenMs });
|
|
124
95
|
expect(Date.now() - startTime).toBeLessThan(delayBetweenMs);
|
|
125
96
|
// Next one added should have had to wait for at least one wait period
|
|
126
|
-
void (() =>
|
|
127
|
-
|
|
128
|
-
expect(Date.now() - startTime).toBeGreaterThanOrEqual(delayBetweenMs);
|
|
97
|
+
void (async () => {
|
|
98
|
+
await prefetcher.enqueue({ value: 5, ms: delayBetweenMs });
|
|
99
|
+
expect(Math.ceil(Date.now() - startTime)).toBeGreaterThanOrEqual(delayBetweenMs);
|
|
129
100
|
prefetcher.done();
|
|
130
|
-
})
|
|
101
|
+
})();
|
|
131
102
|
let lastSeen = 0;
|
|
132
103
|
let loopCount = 0;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const item = _l;
|
|
138
|
-
loopCount++;
|
|
139
|
-
if (item > lastSeen) {
|
|
140
|
-
lastSeen = item;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
145
|
-
finally {
|
|
146
|
-
try {
|
|
147
|
-
if (!_m && !_j && (_k = prefetcher_3.return)) yield _k.call(prefetcher_3);
|
|
104
|
+
for await (const item of prefetcher) {
|
|
105
|
+
loopCount++;
|
|
106
|
+
if (item > lastSeen) {
|
|
107
|
+
lastSeen = item;
|
|
148
108
|
}
|
|
149
|
-
finally { if (e_3) throw e_3.error; }
|
|
150
109
|
}
|
|
151
110
|
expect(loopCount).toBe(5);
|
|
152
111
|
expect(lastSeen).toBe(5);
|
|
153
112
|
// Should require at least 2 batches
|
|
154
|
-
|
|
155
|
-
expect(
|
|
156
|
-
|
|
113
|
+
const duration = Date.now() - startTime;
|
|
114
|
+
expect(duration).toBeLessThan(2.5 * delayBetweenMs);
|
|
115
|
+
expect(Math.ceil(duration)).toBeGreaterThanOrEqual(2 * delayBetweenMs);
|
|
116
|
+
});
|
|
157
117
|
});
|
|
158
118
|
});
|
|
159
119
|
//# sourceMappingURL=iterable-queue-mapper.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-queue-mapper.test.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iterable-queue-mapper.test.js","sourceRoot":"","sources":["../../src/iterable-queue-mapper.test.ts"],"names":[],"mappings":";;AAAA,8BAA8B;AAC9B,mEAA8D;AAC9D,+BAAiC;AACjC,MAAM,KAAK,GAAG,IAAA,gBAAS,EAAC,UAAU,CAAC,CAAC;AAEpC,KAAK,UAAU,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAiC;IAChE,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,UAAU;IACZ,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;YACjD,MAAM,GAAG,GAAG,GAAG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value: true });
|
|
3
3
|
exports.IterableQueue = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const blocking_queue_1 = require("./blocking-queue");
|
|
6
5
|
/**
|
|
7
6
|
* Exposes an `AsyncIterable` interface for the `BlockingQueue`.
|
|
@@ -25,16 +24,14 @@ class IterableQueue extends blocking_queue_1.BlockingQueue {
|
|
|
25
24
|
*
|
|
26
25
|
* @returns Iterator result
|
|
27
26
|
*/
|
|
28
|
-
next() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return { value: item, done: false };
|
|
37
|
-
});
|
|
27
|
+
async next() {
|
|
28
|
+
// Check if queue has an item
|
|
29
|
+
const item = await this.dequeue();
|
|
30
|
+
if (item === undefined) {
|
|
31
|
+
// We finished - There were no more items
|
|
32
|
+
return { value: undefined, done: true };
|
|
33
|
+
}
|
|
34
|
+
return { value: item, done: false };
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
exports.IterableQueue = IterableQueue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-queue.js","sourceRoot":"","sources":["../../src/iterable-queue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iterable-queue.js","sourceRoot":"","sources":["../../src/iterable-queue.ts"],"names":[],"mappings":";;;AAAA,qDAAuE;AAIvE;;;;GAIG;AACH,MAAa,aACX,SAAQ,8BAAsB;IAG9B;;;OAGG;IACH,YAAY,UAAgC,EAAE;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAEM,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI;QACf,6BAA6B;QAC7B,MAAM,IAAI,GAAwB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAEvD,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,yCAAyC;YACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;SACzC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACtC,CAAC;CACF;AAjCD,sCAiCC"}
|