event-loop

How would you implement a basic event-loop?

隐身守侯 提交于 2019-11-26 15:01:17
问题 If you have worked with gui toolkits, you know that there is a event-loop/main-loop that should be executed after everything is done, and that will keep the application alive and responsive to different events. For example, for Qt, you would do this in main(): int main() { QApplication app(argc, argv); // init code return app.exec(); } Which in this case, app.exec() is the application's main-loop. The obvious way to implement this kind of loop would be: void exec() { while (1) { process

What is the difference between “event loop queue” and “job queue”?

ⅰ亾dé卋堺 提交于 2019-11-26 13:08:00
问题 I can not understand how the following code run. Why \"1\" is after \"b\" but \"h\" is after \"3\"? Should\'n the order is: a, b, 1, 2, h, 3? Some article said that the difference between \"event loop queue\" and \"job queue\" leads to following output. But how? I have read the specification of ECMAScript 2015 - 8.4 Jobs and Job Queues, wanting to know how Promise\'job works, but it makes me more confused. Can someone help me? Thank you! var promise = new Promise(function(resolve, reject)

Why is setTimeout(fn, 0) sometimes useful?

此生再无相见时 提交于 2019-11-26 09:58:24
问题 I\'ve recently run into a rather nasty bug, wherein the code was loading a <select> dynamically via JavaScript. This dynamically loaded <select> had a pre-selected value. In IE6, we already had code to fix the selected <option> , because sometimes the <select> \'s selectedIndex value would be out of sync with the selected <option> \'s index attribute, as below: field.selectedIndex = element.index; However, this code wasn\'t working. Even though the field\'s selectedIndex was being set

What is the intention behind clause 2.2.4 of Promise/A+ spec?

五迷三道 提交于 2019-11-26 08:37:13
问题 Clause 2.2.4 of the promise/a+ spec says: onFulfilled or onRejected must not be called until the execution context stack contains only platform code. Then in the notes it states that: Here “platform code” means engine, environment, and promise implementation code. In practice, this requirement ensures that onFulfilled and onRejected execute asynchronously, after the event loop turn in which then is called, and with a fresh stack. Is the intention of this to ensure that when there is a large

What exactly is a Node.js event loop tick?

断了今生、忘了曾经 提交于 2019-11-26 04:59:17
问题 I\'ve been getting more into the internals of the Node.js architecture, and a term I see coming up a lot is \"tick\" as in \"next tick of the event loop\" or the function nextTick(). What I haven\'t seen is a solid definition of what exactly a \"tick\" is. Based on various articles (such as this one), I\'ve been able to piece a concept together in my head, but I\'m not sure how accurate it is. Can I get a precise and detailed description of a Node.js event loop tick? 回答1: Remember that while

Understanding the Event Loop

时光毁灭记忆、已成空白 提交于 2019-11-26 03:20:56
问题 I am thinking about it and this is what I came up with: Let\'s say we have a code like this: console.clear(); console.log(\"a\"); setTimeout(function(){console.log(\"b\");},1000); console.log(\"c\"); setTimeout(function(){console.log(\"d\");},0); A request comes in, and JS engine starts executing the code above step by step. The first two calls are sync calls. But when it comes to setTimeout method, it becomes an async execution. But JS immediately returns from it and continue executing,

Nodejs Event Loop

南楼画角 提交于 2019-11-26 00:45:02
问题 Are there internally two event loops in nodejs architecture? libev/libuv v8 javascript event loop On an I/O request does node queue the request to libeio which in turn notifies the availability of data via events using libev and finally those events are handled by v8 event loop using callbacks? Basically, How are libev and libeio integrated in nodejs architecture? Are there any documentation available to give a clear picture of nodejs internal architecture? 回答1: I have been personally reading

Difference between microtask and macrotask within an event loop context

给你一囗甜甜゛ 提交于 2019-11-26 00:35:10
问题 I\'ve just finished reading the Promises/A+ specification and stumbled upon the terms microtask and macrotask: see http://promisesaplus.com/#notes I\'ve never heard of these terms before, and now I\'m curious what the difference could be? I\'ve already tried to find some information on the web, but all I\'ve found is this post from the w3.org Archives (which does not explain the difference to me): http://lists.w3.org/Archives/Public/public-nextweb/2013Jul/0018.html Additionally, I\'ve found

Tkinter: How to use threads to preventing main event loop from “freezing”

旧街凉风 提交于 2019-11-26 00:07:00
问题 I have a small GUI test with a \"Start\" button and a Progress bar. The desired behavior is: Click Start Progressbar oscillates for 5 seconds Progressbar stops The observed behavior is the \"Start\" button freezes for 5 seconds, then a Progressbar is displayed (no oscillation). Here is my code so far: class GUI: def __init__(self, master): self.master = master self.test_button = Button(self.master, command=self.tb_click) self.test_button.configure( text=\"Start\", background=\"Grey\", padx=50

Why is setTimeout(fn, 0) sometimes useful?

旧街凉风 提交于 2019-11-25 22:13:30
问题 I\'ve recently run into a rather nasty bug, wherein the code was loading a <select> dynamically via JavaScript. This dynamically loaded <select> had a pre-selected value. In IE6, we already had code to fix the selected <option> , because sometimes the <select> \'s selectedIndex value would be out of sync with the selected <option> \'s index attribute, as below: field.selectedIndex = element.index; However, this code wasn\'t working. Even though the field\'s selectedIndex was being set