DEV Community

Discussion on: Cancellable async functions in JavaScript

Collapse
 
getify profile image
Kyle Simpson

The solution presented here isn't really "cancellation", because (as the article acknowledges), the async..await function (aka, the generator) isn't stopped right away, but only silently exits later after it eventually resumes (if ever).

A better approach, IMO, is to proactively stop the generator (using its return() or throw() methods) right away.

CAF is a library I wrote to make such truyly-cancelable async functions easy to write and work with: github.com/getify/CAF