tc39 / proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Other
376 stars 29 forks source link

Name CancelToken.any #46

Closed domenic closed 8 years ago

domenic commented 8 years ago

Possible names:

ljharb commented 8 years ago

Can you elaborate on the semantic/meaning/purpose of this method, to help contextualize the naming?

domenic commented 8 years ago

https://docs.google.com/presentation/d/1kSY7X1ymw5f2oatDrZaMJh4Z_wpd0ynZIimhUyqhbrY/edit?usp=sharing

ljharb commented 8 years ago

Which slide in particular?

domenic commented 8 years ago

I guess my attempts at deep-linking didn't work... slides 20 through 22.

ljharb commented 8 years ago

It seems like either Promise.race or Array#some is the analog here - i think either "race" (for symmetry with Promise) or "some" (for conceptual symmetry with Array.prototype) is probably the best approach? I think "any" might be a better name, but then I think that's a better name for "Array#some" also :-p

domenic commented 8 years ago

The discussions we had for promise are coming back to me now. I think they went something like this...

Now, how do we apply this to cancel tokens? Hmm.

I guess this has me leaning toward either "any" or "race".

ljharb commented 8 years ago

Ah, so you're saying that Promise.any is another possible static method that could exist in the future, that would reject only if all of the promises rejected, and would fulfill if any of them resolved? That makes tons of sense to me.

The counterpart to race could be "together", or "complete", or "finished", or "fufilled", or "settled" - but yeah it's a tricky one.

Given that promises have three states (pending, resolved, rejected), and "race" says "the first one that's not pending wins" - altho cancel tokens have two (pending, cancelled) - "race" might apply best.

domenic commented 8 years ago

Ah, so you're saying that Promise.any is another possible static method that could exist in the future, that would reject only if all of the promises rejected, and would fulfill if any of them resolved? That makes tons of sense to me.

Yeah. I really want it; the problem is designing the "AggregateError" type that you use to signal error if they all reject. I thought that would be a Bikeshed factory. But then again, cancelable promises is going OK, so maybe I should try that :).

ljharb commented 8 years ago

Seems easier than coming up with a way to do Promise.settle and have a way to distinguish rejection from resolution :-p i say go for it! :-D

benjamingr commented 8 years ago

race and any sound equally good and race is terminology we're using for something similar anyway - so +1 on that.

bergus commented 8 years ago

@domenic Don't forget to rename it in Cancel Tokens.md as well