-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Feature Request
Per a conversation over Google Hangouts w/ @benlesh, I was asked to file a ticket for fromWorker to be considered to come back since RxJS 5 (RxJS-DOM).
Is your feature request related to a problem? Please describe.
It's increasingly common for developers to separate work from the main thread using web workers more than ever. RxJS5 made it very convenient to hook a Web Worker to be an Observable to then subscribe to.
Web Worker API was standardized in a way for easy methods to subscribe to values over time as well as cleanly disposing the use of a Web Worker (webWorker.terminate()).
Without it out of the box like what Rxjs.DOM enabled for RxJS 5 in the past, it can become quite redundant & tedious to create an Observable based from a Web Worker script.
Describe the solution you'd like
fromWebWorker is available from rxjs or rxjs/fromWorker as a function that returns Subject<T>:
Example of it being made available
import { fromWorker, Subscription } from "rxjs"
const worker$: Stream<number> = fromWorker<number>('some-worker-involving-numbers.js')
// number is already inferred as `number` from the expression above via TypeScript
const workerSubscription: Subscription = worker$.subscribe( number => console.log(`Number: ${number}`) );
worker$.next([2, 2]))
// Somewhere down the line the worker isn't needed
workerSubscription.unsubscribe();Describe alternatives you've considered
Can't think of any besides its inclusion again
(If this is new operator request) describe reason it should be core operator
N/A
Additional context
@benlesh & I talked about it during a RXJS user group meeting and he liked it enough to instruct me to fill a ticket here.