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
6
votes
2 answers

Callback function executing in the call stack even when it's not empty

When the click event is fired from the mouse, it behaves as expected: First the listener 1 is pushed into the stack where it queues promise 1 in Microtask Queue(or Job Queue). When listener 1 is popped off, the stack becomes empty. And the promise 1…
6
votes
1 answer

How is the event loop never blocking but messages in the queue are run to completion?

I was learning about JavaScript's event loop on the MDN doc. It mentioned that a message in the queue is run to completion, but at the end, it said that the event loop is never blocked. I don't really understand this. Isn't this a contradiction?…
Ha0ran
  • 585
  • 5
  • 13
6
votes
2 answers

What is the difference between callback queue and event queue?

In some of the online resources on asynchronous behavior of JavaScript, concepts like browser architecture, call stack, event loop and event queue are also mentioned. While describing the workings of browser event loop, some use the word event queue…
6
votes
3 answers

are there any simple/example event-driven webservers in C?

There are many example thread based web servers online, but I haven't really seen anything that gives a good example of an event-loop based one (without being very complex, e.g. lighttp and nginx). Are there any? If not, what should I read/look at…
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
6
votes
2 answers

Does a javascript "async" function's body execute in any diferent way if it doesn't have an "await" in it?

From MDN Asynchronous functions operate in a separate order than the rest of the code via the event loop, However I don't understand what that means for a simple function that doesn't return anything explicitly and doesn't use await at all. Is it…
George
  • 181
  • 5
6
votes
1 answer

requests-html "RuntimeError: There is no current event loop in thread 'Thread-1' when using it on a flask endpoint

I have a simple flask API with one endpoint that calls a method in another file to render some javascript from a site using request-html @app.route('/renderJavascript') def get_attributes(): return…
6
votes
3 answers

Correct mental model for a Javascript async function's 'await': generator's 'yield' vs. 'promise.then()'?

Which of a generator's yield vs. promise.then() is a more* correct mental model for understanding 'await'? Property comparison, inferred by stepping through the snippet below with a debugger: await: await does not pause/suspend the running async…
AnonEq
  • 267
  • 2
  • 9
6
votes
3 answers

Vertx web-server uses only one event-loop thread while 16 are available

I use Vert.x v3.5.1. There is the simplest sample of code: vertx.createHttpServer() .requestHandler(anyRouter::accept) .listen(8080); In my case the event loop group size is 16 so I expect that my requests…
katrin
  • 1,146
  • 1
  • 13
  • 24
6
votes
0 answers

Why does console.log not appear to enter the event queue if it is a Web API?

Most examples explaining the concurrency model of JavaScript in the browser list three parts: The call stack, the web api's, and the event queue. The normal process which is often described is that Web APIs are not handled by core ECMAScript and are…
Brandon
  • 1,747
  • 2
  • 13
  • 22
6
votes
2 answers

Javascript event loop clarification

I keep seeing explanations of the "Javascript Event Loop" (ie: browser JS runtime event loop) that don't seem plausible to me, and I'm hoping someone can provide some authoritative clarification. My base asssumption is that the JS event loop is just…
gwideman
  • 2,705
  • 1
  • 24
  • 43
6
votes
2 answers

How to use asyncio event loop in library function

I'm trying to create a function performing some asynchronous operations using asyncio, users of this function should not need to know that asyncio is involved under the hood. I'm having a very hard time understanding how this shall be done with the…
J doe
  • 71
  • 1
  • 4
6
votes
2 answers

js while(true){} blocks event loop

setInterval(function(){console.log("hello")},2000); while(true){} "hello" never gets printed. I think event loop runs in a different thread, but here it seems like 'while loop' is preventing the 'event loop' from execution. Can somebody put some…
Jagga
  • 189
  • 2
  • 9
6
votes
2 answers

Two independent async loops in Python

What would be a good approach to execute two asynchronous loops running in parallel in Python, using async/await? I've thought about something like the code below, but can't wrap my head around how to use async/await/EventLoop in this particular…
Jivan
  • 21,522
  • 15
  • 80
  • 131
6
votes
2 answers

Javascript event loop: Where do web api's get executed?

In reading about the JS event loop, I was curious where web api's get executed. For example, in this image, the pink box doesn't have a name (just says "implementation specific"), leaving me to wonder where these web api's get executed. The call…
TheRealFakeNews
  • 7,512
  • 16
  • 73
  • 114
6
votes
4 answers

Is there a C library for GUIs that does not require its own event loop to be used?

I am looking for a GUI toolkit that I can use from plain C, that works at least on Linux and that does not force me to use its own eventloop – I want to use libev for the main loop and have it notify the toolkit library when X events come in or…
thejh
  • 44,854
  • 16
  • 96
  • 107