Skip to content

Commit

Permalink
use linked list for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Jul 17, 2019
1 parent 3d12e02 commit 97ec5f5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Development
- nothing yet

## v0.0.2

Use new version of linked-list

## v0.0.1

First version!
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "promise-blocking-queue",
"version": "0.0.1",
"version": "0.0.2",
"description": "Memory optimized promise blocking queue with concurrency control",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -73,6 +73,6 @@
"typescript": "^3.5.3"
},
"dependencies": {
"linked-list": "^2.0.1"
"linked-list": "^2.1.0"
}
}
5 changes: 1 addition & 4 deletions src/BlockingQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
private readonly _queue = new LinkedList<Node<any, any>>();
private readonly _boundNext: any;
private _activeCount: number = 0;
private _pendingCount: number = 0;

constructor(options: IBlockingQueueOptions) {
super();
Expand Down Expand Up @@ -72,7 +71,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
this._run(item);
} else {
this._queue.append(new Node(item));
this._pendingCount++;
}
return {
enqueuePromise: enqueuePromiseParts.promise,
Expand All @@ -85,7 +83,7 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
}

public get pendingCount(): number {
return this._pendingCount;
return this._queue.size;
}

private _next() {
Expand All @@ -94,7 +92,6 @@ export class BlockingQueue extends (EventEmitter as new() => MessageEmitter) {
const node = this._queue.head;
if (node) {
node.detach();
this._pendingCount--;
this._run(node.item);
} else {
this.emit('empty');
Expand Down

0 comments on commit 97ec5f5

Please sign in to comment.