Do you know what this pattern is called?

Have a function that is invoked whenever work is added and when work is done. That function tries to resolve the work and handle the output.

This way the function that is invoked must have a callback that implementes .then() and .catch(), right?

Why not set the cursor function immediately yourself?

Because it uses the resolve reference or do you mean moving the whole next part into the setImmediate? I suppose that could be done.

I think it'd be best if you just tell people here what it is that you wanted to write

I think the general idea of the implementation was a queued task list that you can await for

Whenever you see while true -> start asking questions

Yes, sir.

/r/node Thread Parent Link - gist.github.com