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 browsers handle observable internally?

Promise is an api given by browser to do time consuming time in asyn manner.Afetr completion of event loop then function is executes in promise.Does observables also handled by browser in same way that is it is also handled by browsers?How…
-1
votes
1 answer

where does nodejs event loop run?

https://medium.com/the-node-js-collection/what-you-should-know-to-really-understand-the-node-js-event-loop-and-its-metrics-c4907b19da4c according to the above blog post,"There is only one thread that executes JavaScript code and this is the thread…
-1
votes
1 answer

Create custom asynchronous function in Node.js

I am trying to learning to asynchronous logic and i have big problems in my head. I know that almost every function in Node.js is asynchronous. I think our node functions are written this way, so the pointer assignment happens in the event loop.…
user7453724
-1
votes
1 answer

Node.js: http.request() triggers after setImmediate()

I'm new in Node, so the following code behavior is not clear to me: function step(iteration) { if (iteration === 10) return; process.nextTick(() => { step(iteration + 1); // Recursive call from nextTick handler. console.log(`nextTick…
Boolean_Type
  • 1,146
  • 3
  • 13
  • 40
-1
votes
3 answers

Why does fs.readFile return in different orders?

Why if you do: for (var i = 0; i < 5; i++) { fs.readFile('file' + i, function(err, data) { console.log('file: ', data); }); } you get different results each time? I'm guessing it has something to do with node's "async" Event Loop but…
LasagnaAndroid
  • 2,815
  • 1
  • 16
  • 20
-1
votes
1 answer

How to reproduce the behavior of Window.ShowDialog()

Short version: How do I pump for messages while at a particular stack frame so I can wait for a custom dialog to return while blocking, just like Window.ShowDialog(). Ideally avoiding async or multiple threads. I am creating a custom Notification…
Marcus10110
  • 509
  • 4
  • 12
-1
votes
1 answer

JavaScript runtime event loop prior art

The only high profile implementation of the event loop model I can name, other than so-called "reactive" systems that came later, is the JavaScript runtime. Was there much prior art of the event-loop architectural model before the implementation of…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
-1
votes
1 answer

Child event order in Node.js

I have an api, its working process is like this: doing some logic, using 1 second's CPU time wait for network IO, and this IO need 1 second too. So, normally this api will need about 2 seconds to respond Then I did a test. I start 10 requests at…
Junnan Wang
  • 627
  • 4
  • 12
-2
votes
2 answers

Difference between setTimeout(fn,0) vs setTimeout(fn,1)

I have this bit of code: setTimeout( () => console.log("setTimeout callback is complete"), 0); fetch("https://api.coingecko.com/api/v3/ping") .then(() => console.log("fetch callback is complete")); // busy-wait for a few seconds: for (let…
-2
votes
1 answer

JavaScript web server: Understanding blocking behavior during request handling

I have a web server that needs to fetch and cache around 1000 items that come from a slow api. I would like the first request and any that hit a ttl expiration to kick off this operation, but then coninue with the request. It has other values to…
Nick Carbone
  • 445
  • 1
  • 4
  • 9
-2
votes
1 answer

While running setTimeout (timeout of 0) and setImmediate together, Why values are changing for same program when we running it again and again

While running setTimeout and setImmediate together, Why values are changing for same program when we running it again and again. (setTimeout's timing is 0). setImmediate(() =>…
-2
votes
1 answer

NodeJs Event loop in libuv and V8?

The NodeJs consists of V8 engine and also libuv library. V8 engine has its own event loop which has call stack , event queue & micro task queue which is used to run our mainland code. The libuv has event loop as well which consist of phases like…
-2
votes
1 answer

Is there any way to make this top-level code synchronous

Codepen link: https://codepen.io/AnirudhMS/pen/poRmjao? Code: console.log('Started script execution.'); (async () => { let promiseWrapper = async () => { setTimeout(() => { console.log("Inside async script."); Promise.resolve(); …
Black Wind
  • 313
  • 1
  • 8
-2
votes
1 answer

Prevent default action with a programatically dispatched event

In this talk at 32:50 the speaker shows this code: const nextClick = new Promise(resolve => { link.addEventListener('click', resolve, { once: true }); }); nextClick.then(event => { event.preventDefault(); // Handle event }); He…
ByteEater
  • 885
  • 4
  • 13
-2
votes
2 answers

Javascript promises setTimeout execution

I have been playing with Promises, but I am having trouble understanding what is happening with the following code: const promise = new Promise((resolve, reject) => { console.log('Promise started') resolve('Success') }) setTimeout(() => { …
Pavan Gangireddy
  • 417
  • 1
  • 3
  • 13
1 2 3
69
70