Skip to content

Instantly share code, notes, and snippets.

@ikorolev93
Created March 20, 2018 06:42
Show Gist options
  • Save ikorolev93/efbcd984c57b6ef34fed93157acb07fb to your computer and use it in GitHub Desktop.
Save ikorolev93/efbcd984c57b6ef34fed93157acb07fb 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment