You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are planning to use greenlet to defer expensive computations to web worker in CRA project ( along with Type script ). To test it out I was playing around with a small example.
Reacted by Evgeniy Kopitsa, Jacob Beltran, JD Costa, Andreo Vieira, Damián, Sam Richard, Arlen Sambrano, Alberto Cantú Gómez, Anthony D'Andrea, Ivan and 1 more
Hi there - your async function is being transpiled to use helper methods, rather than being an actual async function. If you want to use an async function with Greenlet, you need to tell TypeScript and/or Babel to preserve async functions. In tsconfig.json:
{"compilerOptions": {"target": "ES2015"}}
For those interested, you can easily check to see what a function "looks like" when it gets compiled by your build system:
If you run the above in a stock CRA setup, you'll notice the compiled code contains a bunch of references to external variables that Greenlet isn't aware of.
If the tsconfig option doesn't work for folks (perhaps you're still required to support IE11), you can either remove the async/await, or use a String:
// Option 1: use a non-async functionconstgreenletRead=greenlet(msg=>{// you can optionally use promises here instead of async/awaitreturnmsg;})// Option 2: use a stringconstgreenletRead=greenlet(`async function(msg) { return msg;}`)awaitgreenletRead('Hey from greenlet');
Reacted by Claudio Holanda Jr., Axel Bocciarelli, Ben Zenker and Mohamad Yusup
Activity
andreoav commentedon Jul 24, 2019
Same issue here with CRA
developit commentedon Oct 1, 2019
Hi there - your
asyncfunction is being transpiled to use helper methods, rather than being an actual async function. If you want to use an async function with Greenlet, you need to tell TypeScript and/or Babel to preserve async functions. Intsconfig.json:For those interested, you can easily check to see what a function "looks like" when it gets compiled by your build system:
If you run the above in a stock CRA setup, you'll notice the compiled code contains a bunch of references to external variables that Greenlet isn't aware of.
If the tsconfig option doesn't work for folks (perhaps you're still required to support IE11), you can either remove the async/await, or use a String:
JosephScript commentedon Jan 7, 2020
I tried option one and am receiving a new error
uncaught exception: ReferenceError: promise_default is not defined:I'm curious if you have a working example? I need to support IE11.
axelboc commentedon May 25, 2022
It works for me with
return Promise.resolve(msg), though I'm using Storybook, not CRA.