Discussion
You can't cancel a JavaScript promise (except sometimes you can)
game_the0ry: Off topic, but that site has really nice design
pjc50: I like how C# handles this. You're not forced to support cancellation, but it's strongly encouraged. The APIs all take a CancellationToken, which is driven by a CancellationTokenSource from the ultimate caller. This can then either be manually checked, or when you call a library API it will notice and throw an OperationCancelledException.
CharlieDigital: C# has very good support for this.You can even link cancellation tokens together and have different cancellation "roots".
eithed: > Promise itself has no first-class protocol for cancellation, but you may be able to directly cancel the underlying asynchronous operation, typically using AbortController.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
esprehn: [delayed]
runarberg: [delayed]
mohsen1: Back in 2012 I was working on a Windows 8 app. Promises were really only useful on the Windows ecosystem since browser support was close to non existent. I googled "how to cancel a promise" and the first results were Christian blogs about how you can't cancel a promise to god etc. Things haven't changes so much since, still impossible to cancel a promise (I know AbortSignal exists!)
abraxas: and so the thirty year old hackathon continues...
cush: GC can be very slow. Relying on it for control flow is a bold move
augusto-moura: Not that very slow for web applications. Maybe for real time or time-sensitive applications. For most day to day web apps GC pauses are mostly unnoticeable, unless you are doing something very wrong
thomasnowhere: The never-resolving promise trick is clever but what caught me off guard is how clean the GC behavior is. Always assumed hanging promises would leak in long-lived apps but apparently not as long as you drop the references.