Hacker News new | ask | show | jobs
by TravelTechGuy 2698 days ago
Not sure if it had been mentioned already, but I think we could benefit from cancellable Promises.

Many of the modules and libraries currently support Promises, and `async/await`, but try to find a way to cancel a long-running Promise. Some libraries have resorted to using their own mechanisms, and some (e.g. `axios`) resorted to using a withdrawn TC39 proposal.

I'd like a standard, easy way to cancel a Promise. I know it's not simple, and Promises can wrap around other Promises, etc. but if I'm e.g. uploading a large file to a server, there should be an easy way to provide my users with a "cancel" button that works.

1 comments

theres the AbortController [1] that can be used on a few new promise based APIs such as the Fetch API [2]

[1] https://developer.mozilla.org/en-US/docs/Web/API/AbortContro...

[2] https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

But there's no easy way to inject this AbortControl into existing libraries, or use it easily with async/await. I'm looking for an easier standard.