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

Typescript support #4

Closed
motss opened this issue Sep 7, 2018 · 8 comments
Closed

Typescript support #4

motss opened this issue Sep 7, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@motss
Copy link

motss commented Sep 7, 2018

Any love for the Typescript users?

@wilk
Copy link
Owner

wilk commented Sep 7, 2018

Yeah, sure!
I'll rewrite microjob in Typescript so it will be available for typescripter!

@wilk wilk added the enhancement New feature or request label Sep 7, 2018
@nomeyer
Copy link

nomeyer commented Sep 15, 2018

Hey @wilk, thanks for this package & being willing to rewrite it in Typescript!

I'm looking for a clarification – is it currently possible to use it with Typescript (as an untyped library), or is it just not possible before the rewrite?

I was playing around with it and I can't seem to get around this error:

ReferenceError: tslib_1 is not defined
    at anonymous (eval at parentPort.on (/app/node_modules/microjob/src/worker.js:10:5), <anonymous>:9:5)
    at __executor__ (eval at parentPort.on (/app/node_modules/microjob/src/worker.js:10:5), <anonymous>:30:3)
    at MessagePort.parentPort.on (/app/node_modules/microjob/src/worker.js:12:27)
    at MessagePort.emit (events.js:182:13)
    at MessagePort.onmessage (internal/worker.js:66:8)

Thanks!

@motss
Copy link
Author

motss commented Sep 16, 2018

@nomeyer I'm a TypeScript user and have tried using it with TypeScript. Do you have a reduced test case?

@wilk
Copy link
Owner

wilk commented Sep 17, 2018

@nomeyer thank you for using it!
Sorry for the delay: microjob has been rewritten in TS in version 0.2.0 🎉

I invite you all to try it and to open new issues and PRs!

@wilk wilk closed this as completed Sep 17, 2018
@nomeyer
Copy link

nomeyer commented Sep 24, 2018

Hey @wilk, thanks a lot for that release, much appreciated 😁

Unfortunately, I'm still getting the same error (ReferenceError: tslib_1 is not defined) – does it mean anything to you?

FWIW after gradually stripping things out of my worker function I managed to get this to work:

export function doStuff(data: IStuff): Promise<IStuff> {
  console.log(data);
  return Promise.resolve(data);
}

And I get the ReferenceError: tslib_1 is not defined as soon as I add async, like so:

export async function doStuff(data: IStuff): Promise<IStuff> {
  console.log(data);
  return data;
}

@wilk
Copy link
Owner

wilk commented Sep 24, 2018

Hi @nomeyer !

Thank you for using it and for reporting this issue!

Well, I don't understand why it's giving you that error but it makes sense using an async function instead of a sync one with a Promise.resolve call.
However, you should be able to define a doStuff sync function like so:

export function doStuff(data: IStuff): IStuff {
  console.log(data);
  return data;
}

If you think this should be better highlighted inside the docs, then I'll put it asap.

@nomeyer
Copy link

nomeyer commented Sep 24, 2018

Thanks for your quick reply 🙂

If you think this should be better highlighted inside the docs, then I'll put it asap.

No I think the docs are pretty clear that one can use a sync or async function 👍

My jobs are async so I was hoping to do something like this, that's why I'm trying to get async function doStuff to work. I could try to rewrite my worker without async / await but the two examples in my previous example should be equivalent 🤔 I'll see if I can find some time for more experiments.

@wilk
Copy link
Owner

wilk commented Sep 24, 2018

Ok, thanks, then feel free to open a new issue for the related problem 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants