Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async job example #25

Closed
larshp opened this issue Sep 30, 2018 · 6 comments
Closed

async job example #25

larshp opened this issue Sep 30, 2018 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@larshp
Copy link
Contributor

larshp commented Sep 30, 2018

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?

image

@wilk wilk added the bug Something isn't working label Oct 1, 2018
@wilk
Copy link
Owner

wilk commented Oct 1, 2018

Good catch!
I think this bug has been introduced during the TS refactoring.

@wilk
Copy link
Owner

wilk commented Oct 15, 2018

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.

@wilk wilk added the help wanted Extra attention is needed label Oct 15, 2018
@wilk
Copy link
Owner

wilk commented Nov 4, 2018

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.

@ddwwcruz
Copy link

ddwwcruz commented Nov 4, 2018

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.

@ddwwcruz
Copy link

ddwwcruz commented Nov 4, 2018

Also this package requires an experimental part of node anyway. We might as well compile TS to the latest version of JS.

@wilk
Copy link
Owner

wilk commented Nov 4, 2018

@ddwwcruz great suggestion!
Fixed in version v0.3.1 (just shipped) 🎉

@wilk wilk closed this as completed Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants