【发布时间】:2021-03-28 22:43:44
【问题描述】:
我有一个网络工作者,我试图在其中运行尽可能少的异步代码。
我想在我的网络工作者中有一个 while 循环,同时仍然允许处理消息。有没有办法在浏览器中手动更新事件系统?或者至少更新网络工作者的消息?
Node.js (process._tickDomainCallback()) 中似乎有类似的东西,但到目前为止我还没有找到任何用于 web 的东西。
使用setTimeout 不是一种选择。我想要一个解决方案或明确的答案,这根本不可能。
// worker.js
self.onmessage = function(e) {
console.log("Receive Message");
};
while (true) {
UpdateMessages(); // Receive and handle incoming messages
// Do other stuff
}
【问题讨论】:
标签: javascript dom-events web-worker