Skip to content

Commit 97ec5f5

Browse files
committed
use linked list for better performance
1 parent 3d12e02 commit 97ec5f5

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
## Development
66
- nothing yet
77

8+
## v0.0.2
9+
10+
Use new version of linked-list
11+
812
## v0.0.1
913

1014
First version!

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "promise-blocking-queue",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Memory optimized promise blocking queue with concurrency control",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -73,6 +73,6 @@
7373
"typescript": "^3.5.3"
7474
},
7575
"dependencies": {
76-
"linked-list": "^2.0.1"
76+
"linked-list": "^2.1.0"
7777
}
7878
}

src/BlockingQueue.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
3939
private readonly _queue = new LinkedList<Node<any, any>>();
4040
private readonly _boundNext: any;
4141
private _activeCount: number = 0;
42-
private _pendingCount: number = 0;
4342

4443
constructor(options: IBlockingQueueOptions) {
4544
super();
@@ -72,7 +71,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
7271
this._run(item);
7372
} else {
7473
this._queue.append(new Node(item));
75-
this._pendingCount++;
7674
}
7775
return {
7876
enqueuePromise: enqueuePromiseParts.promise,
@@ -85,7 +83,7 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
8583
}
8684

8785
public get pendingCount(): number {
88-
return this._pendingCount;
86+
return this._queue.size;
8987
}
9088

9189
private _next() {
@@ -94,7 +92,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
9492
const node = this._queue.head;
9593
if (node) {
9694
node.detach();
97-
this._pendingCount--;
9895
this._run(node.item);
9996
} else {
10097
this.emit('empty');

0 commit comments

Comments
 (0)