美文网首页
Event Loop浅理解

Event Loop浅理解

作者: 书简_yu | 来源:发表于2019-03-11 16:17 被阅读0次

    event loop

    task queue中取任务

    同步任务立即执行

    异步任务挂起来,可以执行时放入task queue

    执行完再去取任务

    // 同步任务中此为microtask, 会在本轮事件循环的末尾执行
    Promise.resolve().then(() => {
        
        console.log('bbb');
    })
    

    Tasks execute in order, and the browser may render between them
    Microtasks execute in order, and are executed:
    after every callback, as long as no other JavaScript is mid-execution
    at the end of each task

    摘录自第一篇参考文章

    • 参考

    Tasks, microtasks, queues and schedules

    JavaScript 运行机制详解:再谈Event Loop

    js执行机制(promise,setTimeout执行顺序)

    相关文章

      网友评论

          本文标题:Event Loop浅理解

          本文链接:https://www.haomeiwen.com/subject/hvybpqtx.html