Questions tagged [event-loop]

Event loop refers to an infinite cycle of actions which is used for processing data based on callbacks and messages.

An event loop watches for I/O and timer state changes. It queues functions while waiting for unavailable resources, then dispatches them when resources are available.

References

1046 questions
5
votes
3 answers

How to execute a method automatically after entering Qt event loop?

I would like to execute a method which can only be called once my QApplication is displayed, i.e. when it has entered its main event loop exec_(). I'm new to Qt4 (using PyQt4): i was hoping to have a on_start()-like callback, but didn't find one. Do…
neydroydrec
  • 6,973
  • 9
  • 57
  • 89
5
votes
1 answer

Node's Event Loop Phases Callbacks

I was reading about the node's event loop phases, and says that timers: this phase executes callbacks scheduled by setTimeout() and setInterval(). pending callbacks: executes I/O callbacks deferred to the next loop iteration. idle,…
George Paouris
  • 525
  • 4
  • 16
5
votes
0 answers

How to run multiple blocking loops simultaneously in Common Lisp. [Combining cl-async with queues in thread-pool]

I am new to programming, as well as to Common Lisp. I am trying to solve the following problem: There are stream sources (S1, S2, S3), two processors (P1, P2) (by processor I don't mean CPU-processor, but rather processing functions/subsystems), and…
5
votes
2 answers

If there is any pausing/sleeping or events in x86 assembly

I am wondering if there is anything at the assembly level in x86-64 that allows you to sleep/wait, such that no instructions are run until the wait is done. I have seen the WAIT and PAUSE instructions, but I'm not sure they're related. I would…
Lance
  • 75,200
  • 93
  • 289
  • 503
5
votes
0 answers

Nodejs, where do requests queue up if the node is busy?

Say I have an express.js application that exposes an endpoint on localhost:80/api. Let's say the handler has to do synchronous operations (bad idea, I know). Now, let's say the rate at which node processes the requests is lower that the incoming…
smellyarmpits
  • 1,080
  • 3
  • 13
  • 32
5
votes
1 answer

Call Stack & Event loop - why waiting for empty stack?

I know messages come into call stack from the queue when call stack is empty. Wouldn't it be better though, if event loop could push messages from queue directly to call stack without waiting? What reasons are behind this behavior? If the event loop…
Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24
5
votes
2 answers

I don't fully understand JavaScript Threading

Before I dive into the question. Let me state that by Event Loop I am referring to http://en.wikipedia.org/wiki/Event_loop. This is something that browsers implement. For more information, read this:…
Tower
  • 98,741
  • 129
  • 357
  • 507
5
votes
0 answers

Is there exact order of execution of event listener callbacks and MutationObserver callbacks?

I add several event listeners to input: ['input', 'keydown'].forEach(eventName => { document.getElementById('my-input').addEventListener(eventName, e => { console.log(`${eventName} event is handled'); }) }) Also I add mutation observer…
Yuriy
  • 1,370
  • 4
  • 14
  • 30
5
votes
1 answer

timeout loop in promise never executes after promise is resolved?

I'm running into an issue where a callback sent to setTimeout from a resolved promise never get executed. supposed I have the following: class Foo { constructor(foo) { this.foo = foo; } async execUntilStop(callback) { const…
rudolph9
  • 8,021
  • 9
  • 50
  • 80
5
votes
2 answers

Angular: detect changes inside expensive synchronous function

I have a function which executes an expensive synchronous task. In my case it's a client-side pdf generation through pdfkit, but let's just emulate it with a while-loop sleep. I'd like to display a "loading" spinner before running the task, and hide…
5
votes
1 answer

How promise callbacks are scheduled vs setTimeout, by JS engines or browser/Node external API?

I am considering entire JS environment in two different parts in the question. JS engine Browser API, Node API (External to JS engine). JavaScript engines(V8, SpiderMonkey) are single threaded and prior to ES6 there was no mechanism to run async…
Akshay Naik
  • 669
  • 1
  • 6
  • 22
5
votes
2 answers

asyncio: Event vs Future for synchronization

I'm going through some asyncio source for networking and implementation raised a question in my head. To create a non-blocking I/O when waiting for the data to arrive from a socket, asyncio.StreamReader.read() at its end calls _wait_for_data method…
Radek Kysely
  • 100
  • 1
  • 7
5
votes
2 answers

Promise.resolve vs new Promise(resolve) in vanilla js

The relevant question told me that resolving to a new promise, which is scheduled for the next loop even though it's immediately resolved. However, the comment part seems to be counter examples. var p1 = Promise.resolve("p1") /* console order will…
Ye Shiqing
  • 1,519
  • 2
  • 15
  • 24
5
votes
1 answer

Javascript background loop

Say we have a loop.js file: longLoop().then(res => console.log('loop result processing started')) console.log('read file started') require('fs').readFile(__filename, () => console.log('file processing started')) setTimeout(() => console.log('timer…
grabantot
  • 2,111
  • 20
  • 31
5
votes
2 answers

Node.js setImmediate executed before I/O callbacks (Event Loop)

Take a look at the following code: var fs = require('fs'); var pos = 0; fs.stat(__filename, function() { console.log(++pos + " FIRST STAT"); }); fs.stat(__filename, function() { console.log(++pos + " LAST STAT"); }); setImmediate(function() { …
Bruno Joaquim
  • 1,423
  • 1
  • 14
  • 15