-
-
Save oojikoo/dd6a08af2d8e0bbbbdf72b75ba31d4c8 to your computer and use it in GitHub Desktop.
Running redux-saga in a web worker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {theSaga} from "somewhere"; | |
| const ctx: Worker = self as any; | |
| const workerIO: RunSagaOptions<Action, undefined> = { | |
| subscribe: cb => { | |
| const listener = (ev: MessageEvent) => cb(ev.data); | |
| ctx.addEventListener("message", listener); | |
| return () => ctx.removeEventListener("message", listener); | |
| }, | |
| dispatch: action => ctx.postMessage(action), | |
| }; | |
| runSaga(workerIO, theSaga); |
Author
this was an idea to our project, too. I didn't implement it at the end.
the original one is https://gist.github.com/deadNightTiger/efbcd984c57b6ef34fed93157acb07fb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@oojikoo could you please add some comments and explain what is happening here? We're trying currently to do something similar in our project. Would appreciate any advise. Thanks!