title: How to detect when you are ready to use functions loaded in asm.js module
body: <p>I'm using emscripten to generate a file a.wasm.js that contains functions in C++ for encryption. The webassembly functions take in and return C-strings that hold JSON data. I want to wrap these asm.js functions for more convenient use in my client application. Unfortunately doing it directly inside body.onload doesn't seem to work so I'm using the following hack:</p>
  <pre><code>        &lt;script&gt;
              !function(e, t){
                  console.log(&quot;Loading client...&quot;);
                  var n = &quot;a.wasm.js&quot;;
                  if(!e.WebAssembly){
                      n = &quot;a.js&quot;
                  }
                  console.log(&quot;Script set to &quot; + n);
                  var o = t.createElement(&quot;script&quot;);
                  o.async = true, o.type = &quot;text/javascript&quot;, o.src = n, o.onerror = function(t) {
                      console.error(&quot;Script Error&quot;), console.error(t), setTimeout(function() {
                          e.location.reload(!0)
                      }, 3e3)
                      
                  };
                  var r = t.getElementsByTagName(&quot;script&quot;)[0];
                  r.parentNode.insertBefore(o, r)
              }(window, document);
          &lt;/script&gt;
          &lt;script&gt;
              setTimeout(function(){
                  let _generateKeyPair = Module.cwrap('generateKeyPair', 'string', null);
                  window.generateKeyPair = function() {
                      return JSON.parse(_generateKeyPair());
                  }
              }, 1000)
          &lt;/script&gt;
  </code></pre>
  <p>Of course, the problem here is that I cannot use &quot;generateKeyPair&quot; until 1 second after the app is loaded.</p>
  <p>Is there any callback I can hook in to to know that the asm.js Module object has fully loaded and I can start to use the functions defined within it?</p>