title: How to implement nonblocking event loop in Duktape?
body: <p>I'm embedding Duktape into esp32 which runs FreeRTOS.</p>
  
  <p>And I'm stuck with implementing a nonblocking event loop.</p>
  
  <p>As I understood it is pretty trivial to implement an event loop in terms of async-yield. But it is not very nice because it will always load a CPU even if there is nothing really happening except for waiting for the event to occur.
  I'm thinking about adding another Duktape thread to a Duktape heap where my application is running. And make this separate Duktape thread run by another RTOS task with mutex as sync.</p>
  
  <p>But also there is written that this can lead to issues with garbage collection.</p>
  
  <p>And also as I understand, I will need to take mutex in every native C function that is bound to js functions inside the heap, and that is a little bit inconvenient.</p>
  
  <p>Maybe I miss some simpler way to create such an event loop?</p>
  
  <p>What I need event loop for: execute callback for GUI and run timers. But I need it to sleep when nothing is to do.</p>