Cancelation does not fit the Promise ontology. A Promise does not abstract a process. It abstracts a value. It makes sense to say “I’d like to cancel this process” but it does not make sense to say “I’d like to cancel this value”.
The point of the Promise abstraction is to enable the value to be transformed without having to think about when or if that value will exist. Yes, sometimes the value is produced by asynchronous code execution. But this is not the concern of the Promise. The concern of the Promise is simply to run the queued transformations when that value exists. If you need to cancel a process, then you need to build a cancelation mechanism into an abstraction of the process itself. The Task monad is one example: http://folktale.origamitower.com/docs/v2.0.0/migrating/from-data.task/
A Task can resolve to a Promise just as an asynchronous process eventually produces a value. It can also resolve to a Future, which is just another way of representing the value. The point is that there are two things here: processes and values. Cancelability is a property of the process. Promise is a representation of the value.
I agree, but I really wish people would use the term “break” for promises. When I think about it that way, I think “if I break a promise, I don’t know what will happen.” With that in mind, I feel like breaking a promise – a cancelation in worse terms – says, “I don’t care about this value anymore and I don’t care about anything that was being done to calculate it”. A promise in that mindset can be broken and its state entirely discarded. A task might need to handle a cancellation request carefully, e.g. releasing resources, etc.
Put another way, canceling a promise issues s SIGKILL to the process (in abstract terms) that was calculating the value while canceling a task issues a SIGTERM to a process that is doing something, whether or not that process was returning a value, and allows it to end gracefully.
I think none of these approaches cancel/close the underlying resource, except for using observables? Is there any timeline on when fetch is going to support aborting, now that the cancel proposal for Promises has been rejected.
AbortSignal and AbortController are in the WHATWG DOM spec now, and Firefox and Edge already support it. So I suppose the timeline is “whenever the other major browsers implement it”.