Closed larshp closed 5 years ago
Good catch! I think this bug has been introduced during the TS refactoring.
This problem is related to TS: the worker thread is run-time JS and it gets some JS-compiled from TS.
However, when you compile an async function
via TS, you'll get the __awaiter
wrapper that's not defined inside the worker thread.
I'm trying to figure out how to pass all the compiled TS and not just a little part of it.
After further investigation, I think I need to rewrite microjob back to JS, leaving just the typings definition.
Unfortunately, the function in charge of wrapping the async job is created at run-time and this does not fit with TS compilation.
As explained here: https://basarat.gitbooks.io/typescript/docs/async-await.html the compilation of async functions is done through generators and that just does not work with native await
keyword.
Having a mix of run-time JS and compiled TS is basically bad.
Not really? __awaiter
is made because TS attempts to make async/await usable by versions of node that don't have it. In my experience setting target to es2017 works for this sort of thing.
Also this package requires an experimental part of node anyway. We might as well compile TS to the latest version of JS.
@ddwwcruz great suggestion! Fixed in version v0.3.1 (just shipped) 🎉
Hi, I tried adding the async example as a test case, see https://github.com/larshp/microjob/commit/5dd6c7b5bdf6110c59fe88cf476b15583906877e
It gives
Error: __awaiter is not defined
, am I doing something wrong, missing any black magic?