worker.postMessage({from: fromNumber, to: toNumber});
职程响应时,调用
postMessage()
,发送素数数组。
postMessage(primes);
发送消息的频率没有限制。例如,创建职程之后,你可以调用
postMessage()
发送
一些工作,然后闲置一会,再调用
postMessage()
发送更多工作。
Web
职程也可以
使用
setTimeout()
和
setInterval()
函数安排定期工作。
停止职程有两种方法。第一种,调用
close()
方法停止职程。更常用的方法是,由
创建职程的页面调用
worker.terminate()
关闭职程。由这种方法停止的职程不能
再复活。
9.7.4
参考
完整的代码,包括搜索素数的例程,参见本书的示例代码(
https://github.com/
javascripteverywher ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.