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
-1
votes
1 answer

How to fix This event loop is already running error?

In my project I need to create many connections with discord bots. I have created a function for creating new thread that handles connection (so each thread sould handle one connection) but I am getting Runtime error: this event loop is already…
Ferius
  • 1
  • 1
  • 2
-1
votes
1 answer

Node.js event loop's phase speciality

I'm learning event loop of nodejs. I have some of question after reading in document. Each phase has a FIFO queue of callbacks to execute. While each phase is special in its own way, generally, when the event loop enters a given phase, it will…
ogelacinyc
  • 1,272
  • 15
  • 30
-1
votes
1 answer

Understanding execution of WebAPIs with setTimeout & DOM Api

I have been working with JS for about a year now and I'm still learning it. My question is at the end. In the first example: console.log('Start'); setTimeout(()=> console.log('inside callback'), 0); console.log('End'); outputs Start End inside…
Waleed Ahmad
  • 446
  • 3
  • 15
-1
votes
1 answer

Asyncio errors: CLI - python daemon example but has errors/undesired behavior on exit

I've developed a pattern to use for a commanding a python daemon through cmd module shell using an eventloop. However, its not ready yet because I can't figure out how to gracefully exit the two applications (I'm still learning asyncio and can't…
LeanMan
  • 474
  • 1
  • 4
  • 18
-1
votes
2 answers

block execution by delay function javascript

I am using the following code to see if the JavaScript execution gets blocked while a synchronous function gets into a long loop. function delayBySeconds(sec){ let start = now = Date.now(); while((now - start) < (sec * 1000)){ …
-1
votes
1 answer

microtask vs synchronous code execution order

I'm trying to understand the order of execution of javascript asynchronous code in the event loop. Here's my very short code snippet. How can we explain the actual order of execution: in promise -> end -> in then? Why does the promise constructor…
Eugene Barsky
  • 5,780
  • 3
  • 17
  • 40
-1
votes
1 answer

Invoke a callback in a boost asio GUI loop exactly once per frame

The following problem originates from https://github.com/cycfi/elements/issues/144 which is me struggling to find a way in elements GUI library to invoke a callback once per frame. So far in every library I have seen, there is some callback/explicit…
Xeverous
  • 973
  • 1
  • 12
  • 25
-1
votes
1 answer

Why does function b below (in Node JS) skip iterations?

I was looking into how Node JS executes code. If I set the 'sleep' parameter to 1 in both functions it works as expected. But with different delays in the two functions, it skips iterations for the function with the longest delay. I would expect…
René
  • 3
  • 2
-1
votes
1 answer

In Nodejs context, why the phrase "Don't Block Event Loop" exists even in development it can't be avoided?

Imagine a simple express web app like below. const express = require('express') …
inckka
  • 345
  • 7
  • 21
-1
votes
2 answers

how does clearTimeout actually clears the timeout?

We save the setTimeout reference to be able to cancel it in the future. when we call clearTimeout will it immediately take it out of callback queue or it will wait for the callback's turn and prevent it from running in that point in time here…
Mechanic
  • 5,015
  • 4
  • 15
  • 38
-1
votes
1 answer

How does the webapi execute the settimeout javascript

I have a confusion regarding after the settimeout finishes what does it put in the callback queue does it put the function name/function defination(that we pass as parameter to the settimeout) or the function invoked function cb(){ …
-1
votes
2 answers

Node.js event loop ignores setTimeout inside read stream data events?

I am clarifying a doubt that I have regarding how Node.js executes timers. Normally when having a setTimeout block in your node script, the event loop, even if does not have anything else will wait for specified milliseconds in setTimeout and exits…
Vinay
  • 723
  • 9
  • 32
-1
votes
1 answer

Explain this order of execution of setTimeout and catch handlers

I have this doubt regarding order of execution of Timer functions , microtasks and event listeners : let promise = Promise.reject("Err@!"); setTimeout(() => { promise.catch(er => console.log(er, "Caught !")); //…
Varun Bhalla
  • 415
  • 6
  • 8
-1
votes
1 answer

Why is the Streamlistener reacting differently?

I'm trying to use the Streambuilder in cooperation with Bloc. The problem is that somehow the UI updates only when the expensive Funktions are finished. It seems that then, and only then updates are made to the stream. But I can not figure out…
-1
votes
1 answer

Correct way to run synchronous code in node.js without blocking

I have a websocket server in node.js which allows users to solve a given puzzle. I also have a code that generates random puzzle for about 20 seconds. In the meantime I still want to handle new connections/disconnects, but this synchronous code…
Herokiller
  • 2,891
  • 5
  • 32
  • 50