paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 388 forks source link

process.nextTick? #264

Closed getify closed 10 years ago

getify commented 10 years ago

Regarding: https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1171

I am no expert on this, but I've heard multiple times from different sources that process.nextTick(..) in node.js is not suitable for micro-task scheduling because it doesn't first flush the event loop queue, so it can create starvation (which micro-tasks are meant to avoid, at least with promises). I've heard specifically such assertions in relation to promises, and the conclusion was instead to use setTimeout(..0) or setImmediate(..).

Just figuring someone should research this and get an official answer once and for all. :)

domenic commented 10 years ago

Actually micro-tasks are specifically meant to cause starvation... process.nextTick is the correct choice. Curious where you heard this so I can go correct them :)

cscott commented 10 years ago

@domenic says we're ok. ;)