Just went through this helpful introduction. As of 2022, there seem to be just a few differences to highlight:
ObservableWorker has been deprecated. runWorker is intended to replace it, like this:
import { DoWork, runWorker } from 'observable-webworker';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export class DemoWorker implements DoWork<string, string> {
public work(input$: Observable<string>): Observable<string> {
return input$.pipe(map((data) => `worker response to ${data}`));
}
}
runWorker(DemoWorker);
If you run this code in a browser, you will probably notice that the worker thread continues to stick around after it has run. This is because the workers are kept as part of the inner workings of fromWorker. It will terminate those workers when the subscription is unsubscribed (not just when the observable emits Complete). So this code:
Just went through this helpful introduction. As of 2022, there seem to be just a few differences to highlight:
ObservableWorker
has been deprecated.runWorker
is intended to replace it, like this:fromWorker
. It will terminate those workers when the subscription is unsubscribed (not just when the observable emits Complete). So this code:Should really be this code: