Skip to main content

Posts

Showing posts from December, 2013

Converting synced C/C++ into asynced JavaScript

Emscripten is a C/C++ -> LLVM -> JavaScript compiler. It's useful and interesting, but one of its biggest limitations is about the sync/async model: JavaScript is single-threaded event-driven languages, therefore you cannot do a sleep() in the hope of receiving and processing extra events. Demo First of all, please enjoy this demo , on which I really spent some time. tl;dr Motivation: to make `sleep` and other similar functions actually work in our Runtime, without lots of labor work porting the C/C++ code I actually made it worked  `sync->async` is doable and I think it's not too hard - there are already implementations for JS I think this is a feature that cannot be supported by merely an external library Does it fit emscripten? Or is it possible to write a plugin for emscripten? Demo explained(?) The demo is basically a stop-time animation: //draw something //wait for some while //draw something else //wait... You can verify this