To receive messages, subscribe to the onMessage event
登记onMessage事件以接收信息
This causes the onmessage function in Listing 3 to be invoked.
这将导致清单3中的onmessage的函数的调用。
So what exactly goes on with this onmessage/postMessage paradigm?
那么这个onmessage/postMessage 范型到底说明了什么?
You can see that the Worker script has its own onmessage function.
可以看到,这个Worker脚本拥有自己的onmessage函数。
Next, for each worker being created, you set its onmessage function.
接下来,针对每个所创建的worker,设置其onmessage函数。
The onmessage handler is what will receive this message; you use a simple closure for it.
onmessage处理器将接收这个消息;我们为它使用了一个简单的闭包。
That is why you set this onmessage function back in Listing 2. Each of the other Workers does very similar work.
这就是为什么要设置清单2中的这个onmessage函数的原因所在。其他的每个Workers都做着同样的工作。
To pass this data back, the postMessage function is called, which will invoke the onmessage callback function on the worker, as shown back in Listing 9.
为了将此数据传递回去,调用了 postMessage函数,由该函数在这个worker上调用onmessage回调函数,如清单 9中所示。
To pass this data back, the postMessage function is called, which will invoke the onmessage callback function on the worker, as shown back in Listing 9.
为了将此数据传递回去,调用了 postMessage函数,由该函数在这个worker上调用onmessage回调函数,如清单 9中所示。
应用推荐