process: execute nextTick callback after microtask#8376
Conversation
This fix makes process.nextTick callback always execute after microtasks such as Object.observe and Promise callbacks.
|
Not really because I have not used so much new ES6 features in Node yet. But the process.nextTick callback was changed largely in Node-v0.10 to be called recursively at the end of JS excursion. var http = require('http');
var EE = require('events').EventEmitter;
var obj = {};
function EETest(e) {
Object.observe(obj, function(changeRecord) {
e.addListener('tick', function() {
console.log('tick called', changeRecord);
});
});
process.nextTick(function() {
e.emit('tick');
});
}
EETest(new EE());
obj.a = 1;
http.createServer(function(req, res) {
EETest(new EE());
++obj.a;
}).listen(8080); |
|
Going to use #8325 once updated. |
|
@trevnorris Let me confirm that you think the inconsistent behaviors of callback order between nextTick and microtask cause no issues in the future. |
|
process.nextTick is different from timers and I/O callbacks because it needs to defined its execution timing clearly as the node.js docs says that Microtasks is newly introduced so that user would not distinguish and understand wheather they are the same as timer, I/O callback or not. |
|
@shigeki |
|
@trevnorris Yes, I omitted them since pending queues is hard to write down correctly in the diagram and idle handle of |

The current process.nextTick callback in a main module is executed before microtasks such as callbacks of Object.observe and Promise while not in the other I/O or timer callbacks as below.
$ ~/tmp/oldnode/node-v0.11.13/node test1.js nextTick Object.observe$ ~/tmp/oldnode/node-v0.11.13/node test2.js Object.observe nextTickThese inconsistent behaviors would cause issues in the future use of Object.observe and Promise so this fix makes process.nextTick callback always execute after microtasks.