Coroutines

179 views
Skip to first unread message

Woof

unread,
Oct 9, 2014, 6:00:50 AM10/9/14
to emscripte...@googlegroups.com
I see that coroutine support has been added in the new 1.25.0 release but I can't find any examples or documentation. If I implement my main loop as a coroutine, will calling emscripten_yield() allow the browser to service events?

王璐

unread,
Oct 9, 2014, 8:28:26 AM10/9/14
to emscripte...@googlegroups.com
Not exactly.
The coroutine created by emscripten API must be "stepped" using emscipten_coroutine_next (cannot remember the exact name), so probably one possible way is to write like this:

int main_loop_coroutine(...) {
   ...
   emscripten_yield();
}

int main() {
  auto co = emscripten_coroutine_create(...)
  while(emscripten_coroutine_next(co) {
     emscripten_sleep(1);
  }
  return 0;
}

But an easier way is to write "while(1) { do_something(); sleep(1); }" instead of coroutines.


regards,
- Lu

Woof

unread,
Oct 9, 2014, 8:32:51 AM10/9/14
to emscripte...@googlegroups.com
Thanks - I was looking for alternatives to sleep, since I'm blocked on this:

    https://github.com/kripken/emscripten/issues/2663

Lu Wang

unread,
Oct 9, 2014, 8:34:04 AM10/9/14
to emscripten-discuss
In fact coroutines are implemented in a very similar way as sleep().



regards,
- Lu

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/pI0xEuO68fo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages