when using bluebird and nodejs native Promise to execute the following code, the order of execution is somewhat different. What is the reason for this?
/**
* bluebird, 2 3 5 6 1 4
* Promise 2 3 5 6 4 1
*/
// var Promise = require("bluebird");
setTimeout(() => {
console.log("1");
}, 0);
process.nextTick(function() {
console.log("6");
});
new Promise(function(resolve, reject) {
console.log("2");
var st = new Date().getTime();
while(new Date().getTime() - st < 1000) {}
resolve("ok");
console.log("3");
})
.then(function() {
console.log("4");
});
console.log("5");
question thinking:
1. Native Promise processes then in the micro task queue, so it takes precedence over macro task (setTimeout).
2. What is the handling of then in bluebird?