RXJS extenstions for web worker based on rxjs6
npm install rxjs-webworker
Create an observable from a webworker, path, or function
const fromWorker$ = fromWorker(e => {
const msg = e.data
self.postMessage(msg)
}, 'from worker')
fromWorker$.subscribe(val => {
console.log('val', val)
})
also you can post init messages
fromWorker(e => {
while (count < 1000000) {
count++
}
self.postMessage(`${e.data} ${count}`)
}, 'hello').subscribe(value => {
// hello 1000000
console.log(value)
})
simple map function that runs in a web worker
const mapWorker$ = of('start').pipe(
mapWorker(val => {
return `${val} to end`
})
)
mapWorker$.subscribe(val => {
console.log(val)
})