javascript - native ES6 Promises in browser vs. Node (asynchrony) -
it looks es6 promises async default, without need use process.nexttick
in node (unlike events
instance).
e.g.:
promise.resolve('foo').then(function a() { console.log('bar'); }); console.log('baz');
"baz" gets logged before "bar" appears async.
with node.js, internally accomplished via process.nexttick
or not.
however, browser, how asynchrony achieved native promises? settimeout or other facility?
we can see async well:
new promise(function(resolve){ resolve('foo'); //called synchronously }).then(function(){ console.log('bar'); }); console.log('baz');
("baz" logged first)
Comments
Post a Comment