How to run CPU intensive operations in worker thread in Angular 4 and updating progress in the UI?

Viewed 1318

I see a couple of examples that Jason Teplitz has written about using web workers in Angular 2. The Angular 4 CLI now supports platform-worker that runs the app in a worker thread. The factorial example is a good example of that. Or this step-by-step example.

  1. Using platform-worker guarantee that all the long computational operations run in a web worker? Or should I create another angular module (not the app module) which uses the platform-worker to run the long computation operation? As a result there will be two modules, one for the app and the other for the long operation?

  2. Should I create separate Worker like in this example to create worker threads?

  3. How can I update the UI with the progress of the operation? I assume if the long operation is done in a for loop, it wont get the chance to let the UI know about the progress until that loop is complete? Should I split the long operation into multiple small operations and update the UI?

1 Answers
Related