开发者

What is a browser event loop?

开发者 https://www.devze.com 2023-02-19 08:43 出处:网络
I have been doing some web application programming using GWT and have been confused by the term \"browser event loop\".

I have been doing some web application programming using GWT and have been confused by the term "browser event loop".

I have encountered situations where I need to execute deferred commands and "do something" after the browser event loop completes.

I would like to know as to what ex开发者_如何学JAVAactly it is and what happens during the event loop process and in which order?


A browser event loop is a thread started by the browser that is constantly scanning for and running different events, just like it sounds. As events occur they are put in the event queue and run in turn by the one event thread. Your javascript should not create its own loops waiting for it to complete or anything like that...it will block that one continuous event loop thread. Instead you would use something like setTimeout or setInterval and check for whatever conditions you are waiting for so the browser can do work while it 'waits'.

GWT is nice in that it can co-opt this process somewhat using the scheduler -- in your case where you want to run something after the event loop 'completes' you will probably want to use scheduleFinally or scheduleDeferred. It will inject a handler for a piece of code into the event queue so that it will run after all other code in the current execution context (current execution context == where ever you are in the current JavaScript object hierarchy with the window as the root object) is run but before the next event that is placed in the queue.

0

精彩评论

暂无评论...
验证码 换一张
取 消