@shutterstock/p-map-iterable 0.0.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/LICENSE.md +21 -0
- package/README.md +110 -0
- package/dist/blocking-queue.d.ts +57 -0
- package/dist/blocking-queue.d.ts.map +1 -0
- package/dist/blocking-queue.js +193 -0
- package/dist/blocking-queue.js.map +1 -0
- package/dist/blocking-queue.test.d.ts +2 -0
- package/dist/blocking-queue.test.d.ts.map +1 -0
- package/dist/blocking-queue.test.js +175 -0
- package/dist/blocking-queue.test.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/iterable-mapper.d.ts +104 -0
- package/dist/iterable-mapper.d.ts.map +1 -0
- package/dist/iterable-mapper.js +321 -0
- package/dist/iterable-mapper.js.map +1 -0
- package/dist/iterable-mapper.test.d.ts +2 -0
- package/dist/iterable-mapper.test.d.ts.map +1 -0
- package/dist/iterable-mapper.test.js +1421 -0
- package/dist/iterable-mapper.test.js.map +1 -0
- package/dist/iterable-queue-mapper-simple.d.ts +49 -0
- package/dist/iterable-queue-mapper-simple.d.ts.map +1 -0
- package/dist/iterable-queue-mapper-simple.js +92 -0
- package/dist/iterable-queue-mapper-simple.js.map +1 -0
- package/dist/iterable-queue-mapper-simple.test.d.ts +2 -0
- package/dist/iterable-queue-mapper-simple.test.d.ts.map +1 -0
- package/dist/iterable-queue-mapper-simple.test.js +103 -0
- package/dist/iterable-queue-mapper-simple.test.js.map +1 -0
- package/dist/iterable-queue-mapper.d.ts +73 -0
- package/dist/iterable-queue-mapper.d.ts.map +1 -0
- package/dist/iterable-queue-mapper.js +72 -0
- package/dist/iterable-queue-mapper.js.map +1 -0
- package/dist/iterable-queue-mapper.test.d.ts +2 -0
- package/dist/iterable-queue-mapper.test.d.ts.map +1 -0
- package/dist/iterable-queue-mapper.test.js +174 -0
- package/dist/iterable-queue-mapper.test.js.map +1 -0
- package/dist/iterable-queue.d.ts +26 -0
- package/dist/iterable-queue.d.ts.map +1 -0
- package/dist/iterable-queue.js +34 -0
- package/dist/iterable-queue.js.map +1 -0
- package/dist/iterable-queue.test.d.ts +2 -0
- package/dist/iterable-queue.test.d.ts.map +1 -0
- package/dist/iterable-queue.test.js +252 -0
- package/dist/iterable-queue.test.js.map +1 -0
- package/dist/queue.d.ts +9 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +33 -0
- package/dist/queue.js.map +1 -0
- package/dist/queue.test.d.ts +2 -0
- package/dist/queue.test.d.ts.map +1 -0
- package/dist/queue.test.js +75 -0
- package/dist/queue.test.js.map +1 -0
- package/package.json +45 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
=====================
|
|
3
|
+
Copyright (c) `2022` `Shutterstock, Inc.`
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
|
|
3
|
+
# Overview
|
|
4
|
+
|
|
5
|
+
Async iterable that maps an async iterable input with backpressure.
|
|
6
|
+
|
|
7
|
+
A common use case for `pMapIterable` is as a "prefetcher" that will fetch, for example, DB or remote REST responses. By prefetching items the consumer is able to use 100% of the JS thread time for processing prefetched items instead of waiting for an item to arrive after each item is processed. This use case is most common in batch or queue consumers, not as much in request/response services.
|
|
8
|
+
|
|
9
|
+
# Installation
|
|
10
|
+
|
|
11
|
+
`npm i @shutterstock/p-map-iterable`
|
|
12
|
+
|
|
13
|
+
# Features
|
|
14
|
+
|
|
15
|
+
- `IterableMapper`
|
|
16
|
+
- Interface and concept based on: [p-map](https://github.com/sindresorhus/p-map)
|
|
17
|
+
- Allows a sync or async iterable input
|
|
18
|
+
- User supplied sync or async mapper function
|
|
19
|
+
- Exposes an async iterable interface for consuming mapped items
|
|
20
|
+
- Allows a maximum queue depth of mapped items - if the consumer stops consuming, the queue will fill up, at which point the mapper will stop being invoked until an item is consumed from the queue
|
|
21
|
+
- This allows mapping with back pressure so that the mapper does not consume unlimited resources (e.g. memory, disk, network, event loop time) by racing ahead of the consumer
|
|
22
|
+
- `IterableMapperSimple`
|
|
23
|
+
- Wraps `IterableMapper`
|
|
24
|
+
- Discards results as they become available
|
|
25
|
+
- Exposes any accumulated errors through the `errors` property instead of throwing an `AggregateError`
|
|
26
|
+
- Retains the backpressure functionality of `IterableMapper`'s `enqueue` in that addtional items cannot be added if the max number of items are already queued and their mappers have not yet completed, but does not require that the results be read by the caller before the next item can be mapped since the results are discarded immediately after they are available
|
|
27
|
+
|
|
28
|
+
# `IterableMapper`
|
|
29
|
+
|
|
30
|
+
See [p-map](https://github.com/sindresorhus/p-map) docs for a good start in understanding what this does.
|
|
31
|
+
|
|
32
|
+
The key difference between `IterableMapper` and `pMap` are that `IterableMapper` does not return when the entire mapping is done, rather it exposes an iterable that the caller loops through. This enables results to be processed while the mapping is still happening, while optionally allowing for back pressure to slow or stop the mapping if the caller is not consuming items fast enough. Common use cases include `prefetching` items from a remote service - the next set of requests are dispatched asyncronously while the current responses are processed and the prefetch requests will pause when the unread queue fills up.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { IterableMapper } from '@shutterstock/p-map-iterable';
|
|
36
|
+
import { promisify } from 'util';
|
|
37
|
+
const sleep = promisify(setTimeout);
|
|
38
|
+
|
|
39
|
+
class SleepIterator implements AsyncIterable<number> {
|
|
40
|
+
private _max: number;
|
|
41
|
+
private _current = 1;
|
|
42
|
+
|
|
43
|
+
constructor(max: number) {
|
|
44
|
+
this._max = max;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
48
|
+
for (let i = 0; i < this._max; i++) {
|
|
49
|
+
await sleep(1 * (i % 10));
|
|
50
|
+
|
|
51
|
+
if (this._current <= this._max) {
|
|
52
|
+
yield this._current;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this._current++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const max = 100;
|
|
61
|
+
const iterator = new SleepIterator(max);
|
|
62
|
+
let total = 0;
|
|
63
|
+
let callCount = 0;
|
|
64
|
+
|
|
65
|
+
// Create an item prefetcher with IterableMapper
|
|
66
|
+
// Use `npm i it-batch`'s `batch` function to batch the source iterable
|
|
67
|
+
// into batches of a specific size, such as 50, if making batch requests
|
|
68
|
+
// to a remote service.
|
|
69
|
+
const prefetcher = new IterableMapper(
|
|
70
|
+
// Batch example:
|
|
71
|
+
// batch(iterator, 50),
|
|
72
|
+
iterator,
|
|
73
|
+
// Batch example:
|
|
74
|
+
// async (values: number[]): Promise<number> => {
|
|
75
|
+
async (value: number): Promise<number> => {
|
|
76
|
+
callCount++;
|
|
77
|
+
total += value;
|
|
78
|
+
|
|
79
|
+
// Simulate fetching an async item with varied delays
|
|
80
|
+
await sleep(10 * (callCount % 6));
|
|
81
|
+
|
|
82
|
+
return total;
|
|
83
|
+
},
|
|
84
|
+
{ concurrency: 2, maxUnread: 10 },
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
let lastTotal = 0;
|
|
88
|
+
let loopCount = 0;
|
|
89
|
+
|
|
90
|
+
// Loop through the prefetched items or batches
|
|
91
|
+
// Will pause and wait for prefetch to complete if none available
|
|
92
|
+
// Will immediately start processing if prefetched item or batch is already available
|
|
93
|
+
// If the `maxUnread` count was hit then no prefetches will be in progress until an item
|
|
94
|
+
// is returned from the iterable here. Once an item is returned a mapper
|
|
95
|
+
// will be started; this will repeat until `concurrency` mappers are running again.
|
|
96
|
+
for await (const item of prefetcher) {
|
|
97
|
+
loopCount++;
|
|
98
|
+
if (item > lastTotal) {
|
|
99
|
+
lastTotal = item;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
# Contributing - Setting up Build Environment
|
|
105
|
+
|
|
106
|
+
- `nvm use`
|
|
107
|
+
- `npm i`
|
|
108
|
+
- `npm run build`
|
|
109
|
+
- `npm run lint`
|
|
110
|
+
- `npm run test`
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface BlockingQueueOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Number of pending unread items.
|
|
4
|
+
*
|
|
5
|
+
* Must be an integer from 0 and up or `Infinity`, must be >= `concurrency`.
|
|
6
|
+
*
|
|
7
|
+
* @default 8
|
|
8
|
+
*/
|
|
9
|
+
readonly maxUnread?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class BlockingQueue<Element> {
|
|
12
|
+
private _options;
|
|
13
|
+
private readonly _unreadQueue;
|
|
14
|
+
private readonly _readersWaiting;
|
|
15
|
+
private readonly _writersWaiting;
|
|
16
|
+
private _doneAdding;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
constructor({ maxUnread }?: BlockingQueueOptions);
|
|
21
|
+
get length(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Indicate that no more items will be enqueued.
|
|
24
|
+
*
|
|
25
|
+
* This releases all readers blocked on `enqueue`
|
|
26
|
+
*/
|
|
27
|
+
done(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Add an item to the queue, wait if the queue is full.
|
|
30
|
+
*
|
|
31
|
+
* @param item Element to add
|
|
32
|
+
*/
|
|
33
|
+
enqueue(item: Element): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets an element when one is ready, waits if none are ready.
|
|
36
|
+
*
|
|
37
|
+
* @returns Element or undefined if queue is empty and `done` has been called
|
|
38
|
+
*/
|
|
39
|
+
dequeue(): Promise<Element | undefined>;
|
|
40
|
+
private releaseAllReaders;
|
|
41
|
+
private areWeDone;
|
|
42
|
+
/**
|
|
43
|
+
* Waits for an item to be ready in the queue
|
|
44
|
+
* @returns Item from the ready queue
|
|
45
|
+
*/
|
|
46
|
+
private readWhenReady;
|
|
47
|
+
/**
|
|
48
|
+
* Waits for an item to be ready in the queue
|
|
49
|
+
*/
|
|
50
|
+
private waitForWrite;
|
|
51
|
+
/**
|
|
52
|
+
* Waits to be able to add an item to the queue when full
|
|
53
|
+
*/
|
|
54
|
+
private waitForRead;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=blocking-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocking-queue.d.ts","sourceRoot":"","sources":["../src/blocking-queue.ts"],"names":[],"mappings":"AAEA,UAAU,oBAAoB;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAOD,qBAAa,aAAa,CAAC,OAAO;IAChC,OAAO,CAAC,QAAQ,CAAiC;IAKjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+B;IAO5D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0C;IAO1E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0C;IAE1E,OAAO,CAAC,WAAW,CAAS;IAE5B;;OAEG;gBACS,EAAE,SAAa,EAAE,GAAE,oBAAyB;IAsBxD,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED;;;;OAIG;IACI,IAAI,IAAI,IAAI;IAcnB;;;;OAIG;IACU,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BlD;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAoCpD,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,SAAS;IAiBjB;;;OAGG;YACW,aAAa;IAgB3B;;OAEG;YACW,YAAY;IAW1B;;OAEG;YACW,WAAW;CAU1B"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockingQueue = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const queue_1 = require("./queue");
|
|
6
|
+
class BlockingQueue {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
constructor({ maxUnread = 8 } = {}) {
|
|
11
|
+
// NOTE: unreadQueue has to be a proper FIFO queue with O(1) removal from the front
|
|
12
|
+
// as we may have O(m) unread items, where m may approach n, and Array.shift()
|
|
13
|
+
// would be O(m) (approaching O(n)) in that case as the array gets large.
|
|
14
|
+
this._unreadQueue = new queue_1.Queue();
|
|
15
|
+
// NOTE: Yes, it is possible to call next() multiple times in parallel (and we
|
|
16
|
+
// have a test that demonstrates that), so we may have multiple readers waiting
|
|
17
|
+
// and thus need a queue not just a single item.
|
|
18
|
+
// The items in the queue are 'resolve' functions that we call when an item
|
|
19
|
+
// is ready.
|
|
20
|
+
this._readersWaiting = new queue_1.Queue();
|
|
21
|
+
// NOTE: Yes, it is possible to call add() multiple times in parallel (and we
|
|
22
|
+
// have a test that demonstrates that), so we may have multiple writers waiting
|
|
23
|
+
// and thus need a queue not just a single item.
|
|
24
|
+
// The items in the queue are 'resolve' functions that we call when an item
|
|
25
|
+
// is ready.
|
|
26
|
+
this._writersWaiting = new queue_1.Queue();
|
|
27
|
+
this._doneAdding = false;
|
|
28
|
+
this._options = { maxUnread };
|
|
29
|
+
// Avoid undefined errors on options
|
|
30
|
+
if (this._options.maxUnread === undefined) {
|
|
31
|
+
throw new TypeError('`maxUnread` must be set');
|
|
32
|
+
}
|
|
33
|
+
// Validate maxUnread option
|
|
34
|
+
if (!((Number.isSafeInteger(this._options.maxUnread) ||
|
|
35
|
+
this._options.maxUnread === Number.POSITIVE_INFINITY) &&
|
|
36
|
+
this._options.maxUnread >= 0)) {
|
|
37
|
+
throw new TypeError(`Expected \`maxUnread\` to be an integer from 0 and up or \`Infinity\`, got \`${maxUnread}\` (${typeof maxUnread})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get length() {
|
|
41
|
+
return this._unreadQueue.length;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Indicate that no more items will be enqueued.
|
|
45
|
+
*
|
|
46
|
+
* This releases all readers blocked on `enqueue`
|
|
47
|
+
*/
|
|
48
|
+
done() {
|
|
49
|
+
// Just mark that we're done adding
|
|
50
|
+
this._doneAdding = true;
|
|
51
|
+
// If there are writers waiting then then they will release the waiting readers
|
|
52
|
+
// The reader that sees the writer count hit zero will clean up
|
|
53
|
+
if (this._writersWaiting.length !== 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// If there are no writers waiting then we release all the readers
|
|
57
|
+
this.releaseAllReaders();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Add an item to the queue, wait if the queue is full.
|
|
61
|
+
*
|
|
62
|
+
* @param item Element to add
|
|
63
|
+
*/
|
|
64
|
+
enqueue(item) {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
if (this._doneAdding) {
|
|
67
|
+
throw new Error('`enqueue` called after `done` called');
|
|
68
|
+
}
|
|
69
|
+
// We always add to the internal queue, we just wait to return if the queue is full
|
|
70
|
+
this._unreadQueue.enqueue(item);
|
|
71
|
+
if (this._readersWaiting.length > 0) {
|
|
72
|
+
// Release a reader if one is waiting for an item
|
|
73
|
+
// Remove the first waiting reader Promise from the queue
|
|
74
|
+
const reader = this._readersWaiting.dequeue();
|
|
75
|
+
if (reader === undefined) {
|
|
76
|
+
throw new TypeError('reader queue returned undefined');
|
|
77
|
+
}
|
|
78
|
+
// Resolve the Promise for a waiting reader
|
|
79
|
+
reader(undefined);
|
|
80
|
+
}
|
|
81
|
+
if (this._unreadQueue.length > this._options.maxUnread) {
|
|
82
|
+
// We wait if the queue is at max length
|
|
83
|
+
yield this.waitForRead();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Gets an element when one is ready, waits if none are ready.
|
|
89
|
+
*
|
|
90
|
+
* @returns Element or undefined if queue is empty and `done` has been called
|
|
91
|
+
*/
|
|
92
|
+
dequeue() {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// Bail out and release all waiters if there are no more items coming
|
|
95
|
+
const done = this.areWeDone();
|
|
96
|
+
if (done) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
// Check if queue has an item
|
|
100
|
+
let item;
|
|
101
|
+
// Get the item if one is ready
|
|
102
|
+
if (this._unreadQueue.length !== 0 && this._readersWaiting.length === 0) {
|
|
103
|
+
// If there are items and no waiters, pop one and return it
|
|
104
|
+
item = this._unreadQueue.dequeue();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// If there are no items and/or there are already waiters, we have to wait for one to be ready
|
|
108
|
+
yield this.waitForWrite();
|
|
109
|
+
item = this._unreadQueue.dequeue();
|
|
110
|
+
}
|
|
111
|
+
if (this._writersWaiting.length > 0) {
|
|
112
|
+
// Release a writer if one is waiting
|
|
113
|
+
// Remove the first waiting reader Promise from the queue
|
|
114
|
+
const writer = this._writersWaiting.dequeue();
|
|
115
|
+
if (writer === undefined) {
|
|
116
|
+
throw new TypeError('writer queue returned undefined');
|
|
117
|
+
}
|
|
118
|
+
// Resolve the Promise for a waiting writer
|
|
119
|
+
writer(undefined);
|
|
120
|
+
}
|
|
121
|
+
return item;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
releaseAllReaders() {
|
|
125
|
+
// Release all the waiting readers since we're done
|
|
126
|
+
let waiter;
|
|
127
|
+
while ((waiter = this._readersWaiting.dequeue()) !== undefined) {
|
|
128
|
+
waiter(undefined);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
areWeDone() {
|
|
132
|
+
if (this._doneAdding) {
|
|
133
|
+
// No more calls to `enqueue` will be made
|
|
134
|
+
if (this._writersWaiting.length === 0) {
|
|
135
|
+
// No `enqueue` calls are waiting to add an item
|
|
136
|
+
if (this._unreadQueue.length === 0) {
|
|
137
|
+
// There are no unread items left
|
|
138
|
+
this.releaseAllReaders();
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Waits for an item to be ready in the queue
|
|
147
|
+
* @returns Item from the ready queue
|
|
148
|
+
*/
|
|
149
|
+
readWhenReady() {
|
|
150
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
// If there are waiters, create a waiter promise and add to end of list
|
|
152
|
+
// Note: the background reader removes the promise from the readers waiting queue
|
|
153
|
+
const itemReady = new Promise((resolve) => {
|
|
154
|
+
this._readersWaiting.enqueue(resolve);
|
|
155
|
+
});
|
|
156
|
+
// Wait for our item to be ready
|
|
157
|
+
yield itemReady;
|
|
158
|
+
const item = this._unreadQueue.dequeue();
|
|
159
|
+
// Pull the item from the front
|
|
160
|
+
return item;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Waits for an item to be ready in the queue
|
|
165
|
+
*/
|
|
166
|
+
waitForWrite() {
|
|
167
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
// If there are waiters, create a waiter promise and add to end of list
|
|
169
|
+
// Note: the background reader removes the promise from the readers waiting queue
|
|
170
|
+
const itemReady = new Promise((resolve) => {
|
|
171
|
+
this._readersWaiting.enqueue(resolve);
|
|
172
|
+
});
|
|
173
|
+
// Wait for our item to be ready
|
|
174
|
+
yield itemReady;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Waits to be able to add an item to the queue when full
|
|
179
|
+
*/
|
|
180
|
+
waitForRead() {
|
|
181
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
// If there are waiters, create a waiter promise and add to end of list
|
|
183
|
+
// Note: the background reader removes the promise from the readers waiting queue
|
|
184
|
+
const writeReady = new Promise((resolve) => {
|
|
185
|
+
this._writersWaiting.enqueue(resolve);
|
|
186
|
+
});
|
|
187
|
+
// Wait for our turn to add to the queue
|
|
188
|
+
yield writeReady;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.BlockingQueue = BlockingQueue;
|
|
193
|
+
//# sourceMappingURL=blocking-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocking-queue.js","sourceRoot":"","sources":["../src/blocking-queue.ts"],"names":[],"mappings":";;;;AAAA,mCAAgC;AAkBhC,MAAa,aAAa;IAwBxB;;OAEG;IACH,YAAY,EAAE,SAAS,GAAG,CAAC,KAA2B,EAAE;QAxBxD,mFAAmF;QACnF,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AAuE;YACvE,iFAAiF;YACjF,MAAM,SAAS,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBACxC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,gCAAgC;YAChC,MAAM,SAAS,CAAC;QAClB,CAAC;KAAA;IAED;;OAEG;IACW,WAAW;;YACvB,uEAAuE;YACvE,iFAAiF;YACjF,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBACzC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,wCAAwC;YACxC,MAAM,UAAU,CAAC;QACnB,CAAC;KAAA;CACF;AAxND,sCAwNC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocking-queue.test.d.ts","sourceRoot":"","sources":["../src/blocking-queue.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/// <reference types="jest" />
|
|
5
|
+
const blocking_queue_1 = require("./blocking-queue");
|
|
6
|
+
describe('BlockingQueue', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
// nothing
|
|
9
|
+
});
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
describe('maxUnread: 0', () => {
|
|
14
|
+
it('single item enqueue/dequeue works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 0 });
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
void queue.enqueue(1);
|
|
18
|
+
}, 1000);
|
|
19
|
+
const item = yield queue.dequeue();
|
|
20
|
+
queue.done();
|
|
21
|
+
expect(item).toBe(1);
|
|
22
|
+
}));
|
|
23
|
+
it('dequeue after done does not hang', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 0 });
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
void queue.enqueue(1);
|
|
27
|
+
}, 1000);
|
|
28
|
+
const item = yield queue.dequeue();
|
|
29
|
+
queue.done();
|
|
30
|
+
yield queue.dequeue();
|
|
31
|
+
expect(item).toBe(1);
|
|
32
|
+
}));
|
|
33
|
+
it('enqueue after done throws', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 0 });
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
void queue.enqueue(1);
|
|
37
|
+
}, 1000);
|
|
38
|
+
const item = yield queue.dequeue();
|
|
39
|
+
queue.done();
|
|
40
|
+
yield expect(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return queue.enqueue(2); })).rejects.toThrowError('`enqueue` called after `done` called');
|
|
41
|
+
expect(item).toBe(1);
|
|
42
|
+
}));
|
|
43
|
+
it('balanced enqueue/dequeue works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 0 });
|
|
45
|
+
const writers = [];
|
|
46
|
+
writers.push(queue.enqueue(1));
|
|
47
|
+
writers.push(queue.enqueue(2));
|
|
48
|
+
const readers = [];
|
|
49
|
+
readers.push(queue.dequeue());
|
|
50
|
+
readers.push(queue.dequeue());
|
|
51
|
+
yield Promise.all(writers);
|
|
52
|
+
queue.done();
|
|
53
|
+
yield Promise.all(readers);
|
|
54
|
+
expect(yield readers[0]).toBe(1);
|
|
55
|
+
expect(yield readers[1]).toBe(2);
|
|
56
|
+
}));
|
|
57
|
+
it('full queue blocks enqueue until dequeue', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
59
|
+
// Add first item
|
|
60
|
+
void queue.enqueue(1);
|
|
61
|
+
// Do not wait for second item to add (it will wait until an enqueue completes)
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
void queue.enqueue(2);
|
|
64
|
+
}, 2000);
|
|
65
|
+
const startTime = Date.now();
|
|
66
|
+
expect(yield queue.dequeue()).toBe(1);
|
|
67
|
+
expect(Date.now() - startTime).toBeLessThan(2000);
|
|
68
|
+
expect(yield queue.dequeue()).toBe(2);
|
|
69
|
+
expect(Date.now() - startTime).toBeGreaterThanOrEqual(2000);
|
|
70
|
+
queue.done();
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
describe('maxUnread: 1', () => {
|
|
74
|
+
it('single item enqueue/dequeue works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
76
|
+
yield queue.enqueue(1);
|
|
77
|
+
const item = yield queue.dequeue();
|
|
78
|
+
queue.done();
|
|
79
|
+
expect(item).toBe(1);
|
|
80
|
+
}));
|
|
81
|
+
it('dequeue after done does not hang', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
83
|
+
yield queue.enqueue(1);
|
|
84
|
+
const item = yield queue.dequeue();
|
|
85
|
+
queue.done();
|
|
86
|
+
yield queue.dequeue();
|
|
87
|
+
expect(item).toBe(1);
|
|
88
|
+
}));
|
|
89
|
+
it('dequeue after done and empty does not hang', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
91
|
+
yield queue.enqueue(1);
|
|
92
|
+
const item = yield queue.dequeue();
|
|
93
|
+
queue.done();
|
|
94
|
+
yield queue.dequeue();
|
|
95
|
+
expect(item).toBe(1);
|
|
96
|
+
yield queue.dequeue();
|
|
97
|
+
}));
|
|
98
|
+
it('enqueue after done throws', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
100
|
+
yield queue.enqueue(1);
|
|
101
|
+
const item = yield queue.dequeue();
|
|
102
|
+
queue.done();
|
|
103
|
+
yield expect(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return queue.enqueue(2); })).rejects.toThrowError('`enqueue` called after `done` called');
|
|
104
|
+
expect(item).toBe(1);
|
|
105
|
+
}));
|
|
106
|
+
it('balanced enqueue/dequeue works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
108
|
+
const writers = [];
|
|
109
|
+
writers.push(queue.enqueue(1));
|
|
110
|
+
writers.push(queue.enqueue(2));
|
|
111
|
+
const readers = [];
|
|
112
|
+
readers.push(queue.dequeue());
|
|
113
|
+
readers.push(queue.dequeue());
|
|
114
|
+
yield Promise.all(writers);
|
|
115
|
+
queue.done();
|
|
116
|
+
yield Promise.all(readers);
|
|
117
|
+
expect(yield readers[0]).toBe(1);
|
|
118
|
+
expect(yield readers[1]).toBe(2);
|
|
119
|
+
}));
|
|
120
|
+
it('more dequeue than enqueue works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
122
|
+
const writers = [];
|
|
123
|
+
writers.push(queue.enqueue(1));
|
|
124
|
+
writers.push(queue.enqueue(2));
|
|
125
|
+
const readers = [];
|
|
126
|
+
readers.push(queue.dequeue());
|
|
127
|
+
readers.push(queue.dequeue());
|
|
128
|
+
readers.push(queue.dequeue());
|
|
129
|
+
readers.push(queue.dequeue());
|
|
130
|
+
yield Promise.all(writers);
|
|
131
|
+
queue.done();
|
|
132
|
+
yield Promise.all(readers);
|
|
133
|
+
expect(yield readers[0]).toBe(1);
|
|
134
|
+
expect(yield readers[1]).toBe(2);
|
|
135
|
+
expect(yield readers[2]).toBeUndefined();
|
|
136
|
+
expect(yield readers[3]).toBeUndefined();
|
|
137
|
+
}));
|
|
138
|
+
it('full queue blocks enqueue until dequeue', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 1 });
|
|
140
|
+
// Wait for first item to add
|
|
141
|
+
yield queue.enqueue(1);
|
|
142
|
+
// Do not wait for second item to add (it will wait until an enqueue completes)
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
void queue.enqueue(2);
|
|
145
|
+
}, 2000);
|
|
146
|
+
expect(yield queue.dequeue()).toBe(1);
|
|
147
|
+
const startTime = Date.now();
|
|
148
|
+
expect(yield queue.dequeue()).toBe(2);
|
|
149
|
+
const duration = Date.now() - startTime;
|
|
150
|
+
expect(duration).toBeGreaterThanOrEqual(2000);
|
|
151
|
+
queue.done();
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
describe('maxUnread: 2', () => {
|
|
155
|
+
it('no reads until done works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const queue = new blocking_queue_1.BlockingQueue({ maxUnread: 2 });
|
|
157
|
+
const writers = [];
|
|
158
|
+
writers.push(queue.enqueue(1));
|
|
159
|
+
writers.push(queue.enqueue(2));
|
|
160
|
+
yield Promise.all(writers);
|
|
161
|
+
queue.done();
|
|
162
|
+
const readers = [];
|
|
163
|
+
readers.push(queue.dequeue());
|
|
164
|
+
readers.push(queue.dequeue());
|
|
165
|
+
readers.push(queue.dequeue());
|
|
166
|
+
readers.push(queue.dequeue());
|
|
167
|
+
yield Promise.all(readers);
|
|
168
|
+
expect(yield readers[0]).toBe(1);
|
|
169
|
+
expect(yield readers[1]).toBe(2);
|
|
170
|
+
expect(yield readers[2]).toBeUndefined();
|
|
171
|
+
expect(yield readers[3]).toBeUndefined();
|
|
172
|
+
}));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=blocking-queue.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocking-queue.test.js","sourceRoot":"","sources":["../src/blocking-queue.test.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,qDAAiD;AAEjD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,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,GAAS,EAAE;YACjD,MAAM,KAAK,GAAG,IAAI,8BAAa,CAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;YAC1D,UAAU,CAAC,GAAG,EAAE;gBACd,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;YACnC,KAAK,CAAC,IAAI,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC,CAAA,CAAC,CAAC;QAEH,EAAE,CAAC,kCAAkC,EAAE,GAAS,EAAE;YAChD,MAAM,KAAK,GAAG,IAAI,8BAAa,CAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;YAC1D,UAAU,CAAC,GAAG,EAAE;gBACd,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;YACnC,KAA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C,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAE/B,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC3B,KAAK,CAAC,IAAI,EAAE,CAAC;YAEb,MAAM,OAAO,GAAkC,EAAE,CAAC;YAClD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAE9B,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAE3B,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;YACzC,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QAC3C,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IterableMapper } from './iterable-mapper';
|
|
2
|
+
import { BlockingQueue } from './blocking-queue';
|
|
3
|
+
import { IterableQueue } from './iterable-queue';
|
|
4
|
+
import { IterableQueueMapper } from './iterable-queue-mapper';
|
|
5
|
+
import { IterableQueueMapperSimple } from './iterable-queue-mapper-simple';
|
|
6
|
+
import { Queue } from './queue';
|
|
7
|
+
export { IterableMapper, IterableQueueMapper, IterableQueueMapperSimple, BlockingQueue, IterableQueue, Queue, };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,aAAa,EACb,KAAK,GACN,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = exports.IterableQueue = exports.BlockingQueue = exports.IterableQueueMapperSimple = exports.IterableQueueMapper = exports.IterableMapper = void 0;
|
|
4
|
+
const iterable_mapper_1 = require("./iterable-mapper");
|
|
5
|
+
Object.defineProperty(exports, "IterableMapper", { enumerable: true, get: function () { return iterable_mapper_1.IterableMapper; } });
|
|
6
|
+
const blocking_queue_1 = require("./blocking-queue");
|
|
7
|
+
Object.defineProperty(exports, "BlockingQueue", { enumerable: true, get: function () { return blocking_queue_1.BlockingQueue; } });
|
|
8
|
+
const iterable_queue_1 = require("./iterable-queue");
|
|
9
|
+
Object.defineProperty(exports, "IterableQueue", { enumerable: true, get: function () { return iterable_queue_1.IterableQueue; } });
|
|
10
|
+
const iterable_queue_mapper_1 = require("./iterable-queue-mapper");
|
|
11
|
+
Object.defineProperty(exports, "IterableQueueMapper", { enumerable: true, get: function () { return iterable_queue_mapper_1.IterableQueueMapper; } });
|
|
12
|
+
const iterable_queue_mapper_simple_1 = require("./iterable-queue-mapper-simple");
|
|
13
|
+
Object.defineProperty(exports, "IterableQueueMapperSimple", { enumerable: true, get: function () { return iterable_queue_mapper_simple_1.IterableQueueMapperSimple; } });
|
|
14
|
+
const queue_1 = require("./queue");
|
|
15
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAQjD,+FARO,gCAAc,OAQP;AAPhB,qDAAiD;AAU/C,8FAVO,8BAAa,OAUP;AATf,qDAAiD;AAU/C,8FAVO,8BAAa,OAUP;AATf,mEAA8D;AAM5D,oGANO,2CAAmB,OAMP;AALrB,iFAA2E;AAMzE,0GANO,wDAAyB,OAMP;AAL3B,mCAAgC;AAQ9B,sFARO,aAAK,OAQP"}
|