19

I keep hearing V8 has its rudimentary event loop implementation but

  1. couldn't find it
  2. doesn't really make sense to me. Methinks, the simplest design of a JS engine would be to simply run synchronously and let the "embedder" write their own event loop - like nodejs got libuv.

Is there an event loop implementation in v8? If so, could you point me at it?

Novellizator
  • 13,633
  • 9
  • 43
  • 65

1 Answers1

31

Your intuition is right that the event loop is something that embedders should have control over. However, it is also a fundamental abstract concept of the JavaScript programming model. V8's solution is to provide a default implementation that embedders can override; you can find it in the "libplatform" component: https://chromium.googlesource.com/v8/v8/+/master/src/libplatform/default-platform.cc#140

See also Relationship between event loop,libuv and v8 engine

jmrk
  • 34,271
  • 7
  • 59
  • 74
  • As a javascript beginner, I have a doubt, does the event loop and javascript code is running in the same thread? – arunjos007 Oct 25 '18 at 10:50
  • 1
    Effectively yes. The "event loop" isn't really a thing that's running; it's mostly just a queue of callbacks waiting for their turn to run. – jmrk Oct 25 '18 at 21:48
  • @jmrk `event loop` is a queue of callbacks, it makes sense to me. could you suggest a resource where i can get proper understanding of `event loop`? – divine Sep 03 '20 at 23:57
  • Maybe https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop or https://en.wikipedia.org/wiki/Event_loop ? – jmrk Sep 04 '20 at 13:07