What is Javascript atomic execution unit for events?

拟墨画扇 提交于 2019-12-12 03:53:31

问题


The javascript engine is executing a function which in turn calls another function (sequentially) and this goes on for say 5s. Meanwhile, several events were triggered either by the user or programmatically.

Can we take for granted that no event will be handled before the outermost function finishes?

/* Example */

function outermost_function() {
 function inner_function () {
  function innermost_function () {
    return;
  }
 }
}

回答1:


Javascript is single threaded and events are queued in an event loop. JS code does not execute in parallel on the main thread. Code on the main thread is never interrupted.

That being said, it is possible to execute code in parallel with the use of web workers.

There are many excellent articles on the subject of the Javascript event loop, I would recommend starting here



来源:https://stackoverflow.com/questions/41059965/what-is-javascript-atomic-execution-unit-for-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!