title: Minimal working example for emscripten webworker
body: <p>I'm trying to build a basic webworker example in C++ with emscripten. The API looks very simple, but I can't get it working. I actually wanted to implement this functionality in my project, but after failing tried to make a minimal example and it also doesn't work.</p>
  
  <p>I have main.cpp:</p>
  
  <pre><code>#include &lt;emscripten/emscripten.h&gt;
  #include &lt;emscripten/bind.h&gt;
  #include &lt;iostream&gt;
  
  namespace e = emscripten;
  
  int counter = 0;
  
  void cback(char* data, int size, void* arg) {
      std::cout &lt;&lt; "Callback" &lt;&lt; std::endl;
      counter++;
  }
  
  void loop() {
      std::cout &lt;&lt; "Counter: " &lt;&lt; counter &lt;&lt; std::endl;
  }
  
  int main() {
      std::cout &lt;&lt; "Main func." &lt;&lt; std::endl;
      worker_handle worker = emscripten_create_worker("worker.js");
      emscripten_call_worker(worker, "one", 0, 0, cback, (void*)42);
  
      emscripten_set_main_loop(loop, 2, true);
  
      return 0;
  }
  </code></pre>
  
  <p>and worker.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;emscripten/emscripten.h&gt;
  
  extern "C" {
  
  void one(char* data, int size) {
      for(int i=0; i&lt;10; i++) {
          std::cout &lt;&lt; "Worker" &lt;&lt; std::endl;
          emscripten_worker_respond_provisionally(0, 0);
      }
      emscripten_worker_respond(0, 0);
  }
  }
  </code></pre>
  
  <p>compiled via</p>
  
  <pre><code>emcc -std=c++11 main.cpp -o main.js
  emcc -std=c++11 worker.cpp -s EXPORTED_FUNCTIONS="['_one']" -o worker.js
  </code></pre>
  
  <p>and a simple js load via <code>&lt;script&gt;</code> tag on the html side.</p>
  
  <p>Main loads and starts, outputs <code>Main func.</code> and then worker js is downloaded. But neither <code>Worker</code> nor <code>Callback</code> is outputed. No errors reported.</p>