Александр Гурьянов
unread,Apr 15, 2020, 4:41:34 AM4/15/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.