The HEADLESS option is not much tested, and used for testing purposes mainly. But I think that you need to call window.runEventLoop() manually. Even then I imagine there would need to be some minor fixes.
If there is a use case that we should support here though, we can consider that - why do you want to run headless in node? - Alon On Tue, Jan 28, 2014 at 1:51 PM, Dave Nicponski <[email protected]>wrote: > Sorry for the noob question, but here goes. > > # Source code > $ cat headless_main_loop.cc > > #include <stdio.h> > > #include "emscripten/emscripten.h" > > int foo = 0; > > void dummy_loop() { > printf("dummy loop: %d\n", foo++); > if (foo >= 5) > emscripten_cancel_main_loop(); > } > > int main(int argc, char **argv) { > printf("Start\n"); > > emscripten_set_main_loop(dummy_loop, 0, true); // XXX > > printf("Main done.\n"); > return 0; > } > > # Build command for nodejs > $ ~/src/emscripen/emscripten/emcc -Qunused-arguments -Wall -Wextra -Werror > -Wno-unused-parameter -fexceptions -std=c++11 -x c++ -iquote ./src -iquote > ~/src/emscripen/emscripten/system/include/ -I . -DNDEBUG -O2 > src/trash/poc/headless_main_loop.cc -o > build/trash/poc/headless_main_loop.js -s HEADLESS=1 > > # Try with nodejs > $ (dev-test_pb) nodejs trash/poc/headless_main_loop.js > Start > > # Change line XXX from true to false (infinite loop), rebuild > # Try again > $ (dev-test_pb) nodejs trash/poc/headless_main_loop.js > Start > Main done. > > > In both cases, it works as expected if i compile to html and run in a > browser (obviously, without the HEADLESS=1 option). > Specifically, I see this in the console: > > Start > Main done. > dummy loop: 0 > dummy loop: 1 > dummy loop: 2 > dummy loop: 3 > dummy loop: 4 > > ...which is exactly what i'd expect from both node and browser. > > Am I crazy, or shouldn't this work? > > Note that this is both with the default ubuntu install (1.4.9, old) and > the version i'm actually using from head (1.9.0 (commit > 7dc8c2ff08e46c9d9a88ba44bf221a404eeb1e5e)) > > Thanks, > -dave- > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
