什么是浏览器事件循环? [英] What is a browser event loop?

查看:162
本文介绍了什么是浏览器事件循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做使用GWT一些web应用程序和术语浏览器事件循环。

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 exactly it is and what happens during the event loop process and in which order?

推荐答案

一个浏览器的事件循环是由被不断地扫描并运行不同的事件,就像它的声音浏览器启动一个线程。随着事件发生,他们被放置在事件队列和运行又由一个事件线程。你的JavaScript不应该创建自己的循环等待它完成或类似的东西......它会阻止一个连续的事件循环线程。相反,你会使用类似的setTimeout或setInterval的,并检查任何条件,你等了那么同时它等待'浏览器可以做的工作。

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是很好的,因为它可以在一定程度使用scheduler - 在你想要的事件循环后运行的东西你的情况'完成',你可能会想使用scheduleFinally或scheduleDeferred。它会注入了一块code进入事件队列的处理程序,使其在当前执行上下文的所有其他code后运行(当前执行上下文==无论你是在当前的JavaScript对象层次结构中与窗口作为根对象)上运行,但其被放置在队列中的下一个事件之前

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.

这篇关于什么是浏览器事件循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆