Module.then & await issue

25 views
Skip to first unread message

Александр Гурьянов

unread,
Apr 15, 2020, 4:41:34 AM4/15/20
to emscripte...@googlegroups.com
Hi. I using `-s MODULARIZE=1` for my module, inside modern async/await
environment. I think that design of Module.then is not good. As said
Module.then is promise like function, but it returns it self at the
end. So this promise will never ends in await case. I spent a lot of
time to find why all browsers hangs with my code.

Problem can be described as follow:
```
const Module = {}; // const Module = MyCode();
Module.then = function(cb) { // declared in postamble.js
cb(Module);
return Module; // problem place
};
// How I want to use it
const module = await new Promise((resolve) =>
Module.then(resolve));
// here we have intialized module
```

If you paste this code in browser it will hang, because await is never
finished. Module.then will return promise-like object forever, so
browser will call `then` forever.

My suggestion is to remove `return Module` at the end of `then`, or
rename `then` method to avoid name clashing with Promise. At least we
need to change documentation, and notice that problem exists.

Alon Zakai

unread,
Apr 15, 2020, 12:57:39 PM4/15/20
to emscripte...@googlegroups.com
May be related to https://github.com/emscripten-core/emscripten/pull/10697 , see discussion and ongoing work there.

--
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 emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVF8pmdYAdMQD5XpdyOmW%2B7-xZHtbpk7SyzG2uXm3fv0QQ%40mail.gmail.com.

Александр Гурьянов

unread,
Apr 15, 2020, 2:18:28 PM4/15/20
to emscripte...@googlegroups.com
Wow seems a hot topic:) I was so shocked and forget to google it) btw I solved the problem like this 
I think is worth to add it in documentation as workaround. Cause problem still there from 2017. 

Btw, it was fun to solve this problem without help, so mind blowing.

ср, 15 апр. 2020 г. в 23:57, Alon Zakai <alon...@gmail.com>:

Alon Zakai

unread,
Apr 16, 2020, 3:36:19 PM4/16/20
to emscripte...@googlegroups.com
I hope we can fix this soon, but I agree documenting it meanwhile is a good idea.

If someone has a good idea for where in the docs to put that, a PR would be welcome!

Reply all
Reply to author
Forward
0 new messages