Stopping workers with terminate

Not all problems are cumulative. Some have a desired goal state; once it is found, then the program can exit. We've seen that workers communicate their results by posting messages. Now our program is completed, it would be nice to prevent future messages from being received, possibly polluting our results.

In this recipe, we'll see how to use Worker.terminate to immediately stop a Worker.

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.