Код: Выделить всё
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('first timeout');
resolve('1');
},1000);
console.log('2');
setTimeout(() => {
console.log('3');
},1000);
});
myPromise.then((value) => {
console.log("First then received:", value);
setTimeout(() => {
console.log('5');
},0);
}).catch((error) => {
console.log("Caught in catch:", error);
});
Код: Выделить всё
2
first timeout
First then received: 1
3
5
потому что функция setTimeout-5 будет помещена в очередь макрозадач после setTimeout-3.
p>
но результат, когда я пытаюсь запустить узел версии 23,
Код: Выделить всё
2
first timeout
First then received: 1
5
3
Подробнее здесь: https://stackoverflow.com/questions/793 ... r-promises