Event Loop in browser

132 阅读1分钟

1637671625(1).png

event loop

一个场景,浏览器点击事件,但这个事件十分耗时,你不想等待了,想点击执行其他的事件,点击页面其他按钮,但因为js是单线程的,他被阻塞了,你无法进行操作,直到第一次点击事件完成

怎么办?

key:the code for running Ajax settimeout does not live in javascript runtime,but in browser as a web APIs

render queue

浏览器的渲染也像一个回调函数,它必须得等待javascript runtime内的 stack执行完毕,不同的是渲染会比回调有更高的优先级

image.png

while the sysc code run , the render is blocked,then we can't do thing like click or see the response, while the asyn code run ,we given a chance to render when the set stack was clear cause the callback Queue elements go to call stack one by one,so we has interval to run render

scroll event

which also call tons of callback so this is why