joyent/node — pull request #8376 by shigeki (2014-09-15 14:39:17+00:00)
Title: process: execute nextTick callback after microtask

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.
```JS
// test1.js
// check the callback order of process.nextTick and Object.observe in a main module.
var obj = {};

Object.observe(obj, function(changeRecord) {
console.log('Object.observe callback:', changeRecord);
});

process.nextTick(function() {
console.log('process.nextTick');
});
obj.a = 1;
````
```sh
$ ~/tmp/oldnode/node-v0.11.13/node test1.js
nextTick
Object.observe
````
```JS
// test2.js
// check the callback order of process.nextTick and Object.observe in a setTimeout callback
var obj = {};

setTimeout(function() {
Object.observe(obj, function(changeRecord) {
console.log('Object.observe');
});

process.nextTick(function() {
console.log('nextTick');
});
obj.a = 1;
}, 0);
````
```sh
$ ~/tmp/oldnode/node-v0.11.13/node test2.js
Object.observe
nextTick
````
These 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.