News for hackers. Stuff that matters.
Re:Cancelable Promises: Why was this proposal withdrawn? by koolba on Monday December 19, 2016 @08:07AM (#13211111)
> Promises have always been extremely contentious in JS for a couple reasons and Domenic has had the patients of a saint getting the original proposal through so it's totally understandable that he might not want to deal with this anymore especially if people in his org are against it.

I know this is probably a typo (patients => patience) but that spelling seems to work as well.

> So cancelable promises reignite all the old debates plus there's no obvious right way to do it, like should it be a 3rd state which could cause compatibility issues and would add complexity, or should cancellations just be a sort of forced rejection, which would be a lot more backwards compatibility but with less features.

IMHO neither as cancelability isn't a common requirement. People that need it tend to have more complex requirements and end up tying the cancellation to other chains of logic anyway. Also, unlike say catching an error, you generally want all cancellation handlers to fire rather than just the first one (like with errors).

Re:Cancelable Promises: Why was this proposal withdrawn? by zbjornson on Monday December 19, 2016 @11:46AM (#13212668)
It's fairly common to cancel an HTTP request. The new fetch API doesn't let you cancel a request as a consequence of this shortcoming of promises, while XMLHttpRequest does.
Re:Cancelable Promises: Why was this proposal withdrawn? by webartisan on Monday December 19, 2016 @08:33PM (#13216596)
I think cancelling HTTP requests is quite a useful in some scenarios. Eg 1) Say you're fetching heavy json/binary data on an user action, and before data arrives, he changes his action. Not only do ypu download all of the extra data, but the fetch for the next action is slowed down like hell.

Not sure, but does this mean that I can't cancel a heavy file upload if a user changes his mind?

Re:Cancelable Promises: Why was this proposal withdrawn? by pacaro on Monday December 19, 2016 @12:43PM (#13213245)
Herein lies the rub.

So I cancel my GET request, all is fine with the world. I cancel my POST, and now I have no idea at which layer it was cancelled, if at all. Certainly the cancel doesn't propagate to the server.

I've used cancellation in C# and agree that it's super useful, but it's not a panacea and has to be handled thoughtfully. JS can manage without it IMHO

Re:Cancelable Promises: Why was this proposal withdrawn? by Klathmon on Monday December 19, 2016 @01:25PM (#13213637)
The counter-argument to that is what happens when you make a GET request for a 1gb file? Or you POST a 1gb upload?

Canceling them is now a big deal if it's needed.

Personally, I think they could be handled by the WebStreams API, so when you want to "cancel" a download or upload, you just throw in the function which is consuming or creating the actual data which will reject the promise entirely.

However only ReadableStreams are available in some browsers right now, and WritableStreams are still a bit away AFAIK, so it's not possible to do that right now with promises, but i don't think that warrants adding even more features to a language which will most likely never be removed.

Re:Cancelable Promises: Why was this proposal withdrawn? by pacaro on Monday December 19, 2016 @02:11PM (#13214082)
I agree. If you're handling objects of that size in single requests, then you're already in footgun territory. Step carefully.
Re:Cancelable Promises: Why was this proposal withdrawn? by int_19h on Monday December 19, 2016 @06:53PM (#13216109)
Cancellation is a high-level expression of intent that you no longer care about the result of the operation.

Due to the very nature of asynchronous operations, it is, in general, impossible to even determine which layer will ultimately handle that request (e.g. in your example, whether the POST won't happen, or it'll be aborted, or it's already completed), much less how it'll be handled.

The assumption is that all layers will do their best effort (defined vaguely in a "common sense" way) to service that request.

That is a very useful abstraction to have, and I don't see why JS is special in that regard.

Re:Cancelable Promises: Why was this proposal withdrawn? by Manishearth on Monday December 19, 2016 @01:32PM (#13213696)
I mean, this isn't new. When you make a POST request in JS a bad network may mean that it gets delivered but errors out on your end. You need to code your application to be robust to this anyway.
Re:Cancelable Promises: Why was this proposal withdrawn? by pacaro on Monday December 19, 2016 @02:09PM (#13214058)
This. Absolutely.

Those applications that already aren't robust to this (I sadly assume that is most) aren't going to be helped by cancellation

Re:Cancelable Promises: Why was this proposal withdrawn? by cwmma on Monday December 19, 2016 @08:19AM (#13211174)
fixed the spelling and you're right it's not a super common requirement, but it comes up in context of designing APIs to use promises, and if you are trying to add promises to an API that is cancelable, you'd want some way to express that.
Re:Cancelable Promises: Why was this proposal withdrawn? by Rapzid on Monday December 19, 2016 @08:49AM (#13211326)
Do you have any idea what the current direction is(if any?) that they are moving in? I'm mostly familiar with the use of tokens; Golang using Context and C# using CancelationToken.

I currently utilize cancellation tokens myself in nodejs(TypeScript) when creating libraries or wrapping the stdlib event/stream based stuff.

Re:Cancelable Promises: Why was this proposal withdrawn? by cwmma on Monday December 19, 2016 @10:08AM (#13211809)
With this canceled there is no official direction, and any further movement will likely be based on what is decided in the community.