RXJS extensions for adding web worker functionality via operators and observables
Create an observable from a webworker, path, or function
// web worker
const myWorker = new Worker('path/to/web-worker.js');
const observable1 = Observable.fromWorker(myWorker);
// function
const observable2 = Observable.fromWorker(() => {
self.postMessage('Hello World');
});
// string
const observable3 = Observable.fromWorker('path/to/web-worker.js');
simple map function that runs in a web worker
Observable
.from(['Hello World'])
.mapWorker(strng => {
return strng + ', I am from a worker.';
})
.subscribe(res => {
console.log(res); // Hello World, I am from a worker
});
returns either the result or null
Observable
.from(['Hello World'])
.filterWorker(strng => {
return strng === 'Hello World';
})
.subscribe(res => {
console.log(res); // Hello World
});