How to prevent HTML5 Web Workers from locking up thus correctly responding to messages from parent

后端 未结 3 1130
梦谈多话
梦谈多话 2021-02-06 02:45

I\'m using web workers to do some CPU intensive work but have the requirement that the worker will respond to messages from the parent script while the worker is still processin

3条回答
  •  再見小時候
    2021-02-06 03:17

    A worker can spawn sub workers. You can have your main worker act as your message queue, and when it receives a request for a long running operation, spawn a sub worker to process that data. The sub worker can then send the results back to the main worker to remove the event from the queue and return the results to the main thread. That way your main worker will always be free to listen for new messages and you have complete control over the queue.

    --Nick

提交回复
热议问题