直接上代码 , 结果先不说
setTimeout(() => {
console.log(1)
}, 22)
setImmediate(() => {
console.log(2);
})
process.nextTick(() => {
console.log(3);
})
new Promise((resolve, rejects) => {
console.log(4);
resolve(4)
}).then(() => {
console.log(5);
})
console.log(6);
async function test(){
console.log("hello");
await sleep(1000)
console.log('world');
}
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms))
}
test()