How it works...

We've seen in previous chapters how flexible composing promises and async functions can be. Doing so with workers is a natural extension. Consider an asynchronous AJAX request. This could be thought of as taking place in a worker. After all, it is being performed in a different thread of execution, but managed by the browser.

As long as success error conditions are handled properly, promises and async functions can be used to provide familiar interfaces to Web Workers. Having familiar and simple interfaces is crucial when integrating new technology with an existing code base.

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.