# Promise not working

**URL:** <https://talk.observablehq.com/t/promise-not-working/529>\
**Category:** Uncategorized\
**Created:** [March 21, 2018, 11:06am UTC](https://talk.observablehq.com/t/promise-not-working/529 "2018-03-21T11:06:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdwfrost](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/sdwfrost/32/139_2.png) [@sdwfrost](https://talk.observablehq.com/u/sdwfrost)\
**Post date:** [March 21, 2018, 11:07am UTC](https://talk.observablehq.com/t/promise-not-working/529/1 "2018-03-21T11:07:00Z")

</div>

Dear All,

Apologies, as I’m still working through async/await/Promises etc… I was wondering why a promise ‘Module’ in my code (which should wait for the download) seems to resolve too soon, hence breaking the notebook?

[https://beta.observablehq.com/@sdwfrost/emscripten-webassembly-module-example#Module](https://beta.observablehq.com/@sdwfrost/emscripten-webassembly-module-example#Module)

---

<div class="post-metadata">

**Author:** ![tom](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tom/32/2262_2.png) [@tom](https://talk.observablehq.com/u/tom)\
**Post date:** [March 21, 2018, 3:26pm UTC](https://talk.observablehq.com/t/promise-not-working/529/2 "2018-03-21T15:26:36Z")

</div>

You’re discovering some very interesting module loading patterns 🙂

I suspect this one would be pretty confusing even just in JavaScript-land without Observable as an intermediate - the `wassa` module asynchronously loads, within itself, without using anything like AMD or UMD that would handle the asyncness. Digging at the [example HTML file in their repo](https://github.com/noamross/wassa/blob/master/inst/htmlwidgets/lib/emssa/em2.html), they notify when the module is loaded with a `Module.addOnPostRun(` callback, and that works: here’s a working loader cell.

```auto
Module = new Promise(resolve => {
  require(url).catch(() =>
    window.Module.addOnPostRun(() => resolve(window.Module))
  );
})

```

So, it loads the JavaScript, and then waits for the stuff that JavaScript loads (its WebAssembly component, I’d expect), and then returns the usable Module object.

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/sdwfrost/32/139_2.png) [@sdwfrost](https://talk.observablehq.com/u/sdwfrost)\
**Post date:** [March 21, 2018, 4:01pm UTC](https://talk.observablehq.com/t/promise-not-working/529/3 "2018-03-21T16:01:05Z")

</div>

Dear @tom

As you can see from [here](https://noamross.github.io/wassa/inst/doc/adventures-in-webassembly.html), the `addlOnPostRun` function is used for benchmarking, and isn’t a generic pattern at all:

```auto
Module.addOnPostRun(() => { // Run this stuff after the wasm module loads
          var start = window.performance.now(); //start timing
          var result = Module.ssa(x.rate, x.max_time, x.seed); //run our function
          var time = window.performance.now() - start; //stop timing
          el.innerHTML = '<strong>Output: ' + result + '<br />' + //print results
                         'Time Elapsed: ' + Math.round(time) + ' milliseconds</strong>';
          el.setAttribute("style", "margin:5px; padding:5px; border: thin solid #0000FF;");
        });

```

While it doesn’t matter for compilation what this function is, Emscripten has to be told about it (via `-s "EXTRA_EXPORTED_RUNTIME_METHODS=['addOnPostRun']"`). If this wasn’t there, is there any trick I could use within Observable to capture the asyncness?
