相关文章推荐
精明的显示器  ·  access vba textbox ...·  12 月前    · 
严肃的黄瓜  ·  Unity macOS ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Hi I'm really new to Angular and trying to understand web workers.

So far I have two async workers but here is now my problem. The first one is taking too long until it renders the output. The second one has already finished and rendered everything in the frontend. The user can interact with the site even if the first worker isn't ready yet. But this will cause sometimes problems.

So my solution is to encapsulate the tow workers with a promise and call e.g. $q.all() to render the output of both workers when they have finished gathering all needed informations.

But my current understanding for the initialization of web workers is that I can trigger them e.g. in a
- webpack.config.js
- tsconfig.worker.json So I don't know how or if I can't call all workers by my own script.

It should be possible, but not in the traditional way. After 1 minute of Googling I found an article on Codeburst, explaining the what's and how's of async workers:

https://codeburst.io/promises-for-the-web-worker-9311b7831733

In a nutshell: by wrapping a worker in a Class and instantiating that Class , binding the onmessage attribute on construct , you can fully intercept/handle all functionality.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .