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/Await in Worklet Functions #109

Open
robnewton opened this issue Aug 22, 2023 · 2 comments
Open

Async/Await in Worklet Functions #109

robnewton opened this issue Aug 22, 2023 · 2 comments

Comments

@robnewton
Copy link

Is it possible to use async/await within Worklets?

I'm trying to make calls to asynchronous functions outside of the function tagged with the worklet keyword? As a simple example, is it possible to use the Expo FileSystem async functions like copyFileAsync() from within a worklet?

When tried, I get errors like this:

TypeError: Cannot assign to read only property 'message' of object 'SyntaxError: unknown: Unexpected reserved word 'yield'.
@bglgwyng
Copy link
Contributor

You can't do asynchronous things within worklets since they don't run the event loop as far as I know.

However, I didn't expect that async/await syntax is not supported in worklets. The error message indicates that worklets don't support generator syntax which is emitted as a transpilation result of async/await.

@robnewton
Copy link
Author

That makes sense but I was hoping it would just execute synchronously. In this scenario I don't need it to be asynchronous since it's in another thread, I just need to call something which relies on that syntax.

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

No branches or pull requests

2 participants