# Embind module hangs on load

**URL:** <https://talk.observablehq.com/t/embind-module-hangs-on-load/2611>\
**Category:** Uncategorized\
**Created:** [December 4, 2019, 6:48pm UTC](https://talk.observablehq.com/t/embind-module-hangs-on-load/2611 "2019-12-04T18:48:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rreusser](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/rreusser/32/1976_2.png) [@rreusser](https://talk.observablehq.com/u/rreusser)\
**Post date:** [December 4, 2019, 6:48pm UTC](https://talk.observablehq.com/t/embind-module-hangs-on-load/2611/1 "2019-12-04T18:48:25Z")

</div>

I’m trying to compile some C++ via emscripten and run it in the browser. I found issues like [this](https://talk.observablehq.com/t/importing-emscripten-module/722) which had some helpful ideas, but I feel like I’ve followed a relatively simple pathway and can’t quite figure out what’s going wrong.

I’ve created a notebook which pretty fully describes the issue here:

> **[Embind test](https://observablehq.com/d/7ae13549e5ca778c)**
>
> An Observable notebook by Ricky Reusser.

The fundamental problem is that it works pretty effortlessly in `node` and in the browser, but I can’t figure out why it seems to load and run but completely hang in Observable.

To clarify, perhaps my problem in addition to getting it to just work is that I’m having a bit of trouble understanding what Observable might be doing or trying to do, or why after trying this all Observable notebooks hang until I quit the browser.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [December 4, 2019, 7:24pm UTC](https://talk.observablehq.com/t/embind-module-hangs-on-load/2611/2 "2019-12-04T19:24:41Z")

</div>

The problem is that the Initialize method returns a then-able: an object that exposes a then method. The then method resolves with itself, so it goes into an infinite loop. In short, it’s like this:

```auto
{
  const loop = ({then: resolve => resolve(loop)});
  return Promise.resolve(loop);
}

```

You can fix this by deleting the then method, or renaming it:

```auto
{
  const module = Initialize();
  delete module.then;
  return module;
}

```

Here’s the relevant issue:

> <https://github.com/emscripten-core/emscripten/issues/5820>
>
> https://github.com/kripken/emscripten/blob/93479ecbd390aec4f8a3765fe04bcb365d0b31b2/src/postamble.js#L118-L141
> postamble.js adds Module.then when -s MODULARIZE=1 but using it causes indefinite loop on Promise.resolve() and ES2017 await statement.
> By the spec the...

---

<div class="post-metadata">

**Author:** ![rreusser](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/rreusser/32/1976_2.png) [@rreusser](https://talk.observablehq.com/u/rreusser)\
**Post date:** [December 4, 2019, 7:29pm UTC](https://talk.observablehq.com/t/embind-module-hangs-on-load/2611/3 "2019-12-04T19:29:54Z")

</div>

Thanks! Wow, that was not the answer I expected. That solves it immediately. Perhaps `MODULARIZE` is not the option I’m looking for, or perhaps I could kludge around this within the bundle by injecting my own `--post-js`, but I’m willing to go with it and deal with this awkward thing. 🎉
