From 5bfb0a99f91355a78dab445661fad0ccd6b24285 Mon Sep 17 00:00:00 2001 From: Meir Gottlieb Date: Tue, 3 Apr 2018 19:03:23 -0600 Subject: [PATCH] Added call to nextTick in TaskQueue to make sure queue is handled async. --- package.json | 2 +- src/taskQueue.ts | 4 +++- tests/driver/mockCursor.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2a83a39..6457c8a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hydrate-mongodb", "description": "An Object Document Mapper (ODM) for MongoDB.", - "version": "2.0.2", + "version": "2.0.3", "author": { "name": "Artifact Health, LLC", "url": "http://www.artifacthealth.com" diff --git a/src/taskQueue.ts b/src/taskQueue.ts index 25b7107..7beed53 100644 --- a/src/taskQueue.ts +++ b/src/taskQueue.ts @@ -71,6 +71,7 @@ export class TaskQueue extends EventEmitter { else { // this is the first task so initialize the queue and start processing this._head = this._tail = task; + // make sure calls to _process are async process.nextTick(() => this._process()); } } @@ -144,7 +145,8 @@ export class TaskQueue extends EventEmitter { } if(this._head) { - this._process(); + // make sure calls to _process are async + process.nextTick(() => this._process()); } } diff --git a/tests/driver/mockCursor.ts b/tests/driver/mockCursor.ts index 1ff3a3e..f360324 100644 --- a/tests/driver/mockCursor.ts +++ b/tests/driver/mockCursor.ts @@ -110,7 +110,7 @@ export class MockCursor extends Readable implements mongodb.Cursor { next(): Promise; next(callback: mongodb.MongoCallback): void; next(callback?: any): any { - + callback(); } project(value: Object): mongodb.Cursor {