node异步函数类型

2020-03-16  本文已影响0人  RexingLeung

直接上代码 , 结果先不说

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()


上一篇下一篇

猜你喜欢

热点阅读