Skip to content

Instantly share code, notes, and snippets.

@oojikoo
Forked from ikorolev93/index.ts
Created January 7, 2020 02:58
Show Gist options
  • Select an option

  • Save oojikoo/dd6a08af2d8e0bbbbdf72b75ba31d4c8 to your computer and use it in GitHub Desktop.

Select an option

Save oojikoo/dd6a08af2d8e0bbbbdf72b75ba31d4c8 to your computer and use it in GitHub Desktop.
Running redux-saga in a web worker
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);
@t1gor
Copy link
Copy Markdown

t1gor commented Dec 29, 2020

@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!

@oojikoo
Copy link
Copy Markdown
Author

oojikoo commented Jan 5, 2021

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