I\'m combining async.queue and Cursor.nextObject to iterate over a cursor and do some asynchronous work against the returned documents.
There\'
I'm still not sure what's causing the pause, but it seems that is the culprit.
During the pause, Cursor.nextObject is getting called several times before the first returns. Some of these calls are returning null. The solution is to make sure Cursor.nextObject is never called concurrently.
if (this.cursor && !this.cursor_exec && this.length() < this.concurrency) {
this.cursor_exec = true;
this.cursor.nextObject(function(err, item) {
console.log(this.name + ': ' + (item ? item._id : null) + ' ' + (err ? err : null));
this.cursor_exec = false;
if (item) {
this.push(item);
} else {
delete this.cursor;
}
}.bind(this));
}