js事件循环以及promise

async function async1 () {

console.log('async1 start');

await async2();

console.log('async1 end');

}

async function async2 () {

console.log('async2')

}

console.log('script start')

setTimeout(function() {

console.log('setTimeout')

}, 0);

async1();

new Promise(function (r) {

console.log('promise1');

r();

}).then(function() {

console.log('promise2')

});

console.log('script end');

1.事件循环输出顺序

script star   

async1 start

async2

promise

script end 

async1 end 

promise2 

setTimeout

表达上面的promise2

console.log('async1 start');

new Promise(function (r) {

     console.log('async2')

r();

}).then(function() {

console.log('async1 end');

});

相关推荐

  1. js事件循环以及promise

    2024-01-20 12:18:04       46 阅读
  2. js事件循环

    2024-01-20 12:18:04       50 阅读
  3. Node.js 事件循环

    2024-01-20 12:18:04       24 阅读
  4. node.js事件循环相关步骤

    2024-01-20 12:18:04       54 阅读
  5. Node.js 中的事件循环(Event Loop)

    2024-01-20 12:18:04       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-20 12:18:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-20 12:18:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-20 12:18:04       82 阅读
  4. Python语言-面向对象

    2024-01-20 12:18:04       91 阅读

热门阅读

  1. 【QT】QThread 成员函数

    2024-01-20 12:18:04       40 阅读
  2. 十种较流行的网络安全框架及特点分析

    2024-01-20 12:18:04       57 阅读
  3. Curl- go的自带包 net/http实现

    2024-01-20 12:18:04       59 阅读