How it works...

We've seen how the onmessage listener can be used to listen for messages posted from the main thread. Now we can see that the same evenlistener, when binding on the worker reference in the main function, can listen to messages from the worker. We also can see that this listener is isolated from the individual worker being referenced. Each worker has a unique event listener; this is useful for organizing communication between workers.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.