-
Notifications
You must be signed in to change notification settings - Fork 94
Is it possible to use this library with web workers? #257
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
Comments
Hi Harry, Happy you ask, because I actually developed React WebWorker before building React Async. However it does not provide a hook and has less features in general. We actually have plans for a future version of React Async to support subscriptions, which would allow it to be used with a Web Worker. There's work-in-progress which supports subscriptions, but can't find the time to wrap that up into something shippable. |
That looks great, I'll give it a go :). I am using create-react-app and since posting I also experimented with workerize-loader. I'm not sure if it's best practice but the code snippet below seems to work: // eslint-disable-next-line import/no-webpack-loader-syntax
import worker from "workerize-loader!../../worker";
function dispatch({ myArg }) {
let inst = worker();
return inst.myFunction(myArg);
}
export default function MyComponent() {
myArg= ... ;
const { data, error, isPending } = useAsync({
promiseFn: dispatch,
myArg: myArg
});
...
} |
Hey guys - don't want to clutter up your open issues, and my question is answered and problem resolved. Hopefully this thread is useful for others who come across it - closing out |
Hello! Thank you for the library, it's a very nice API and the documentation is fantastic.
After using the library I realised that since my async task is entirely CPU, promises aren't appropriate and I would need to use web workers instead.
Is library a good fit for web workers, or should I look somewhere else? Does anybody have a code snippet where they use react-async with web workers?
Thank you
The text was updated successfully, but these errors were encountered: