This is a good point. I didn't think about passing the same callback more than 
once.

Ideally, if the same resolve & reject callback combination is passed more than 
once, the same promise is always returned (I can't think of a use case where 
promises could stop to work, if promises were specced with this additional 
rule, but maybe I overlooked). So if we pretend that's the case, it seems 
ignore() should deregister all callbacks.

Do you have a use case where the same callback will be passed to the same 
promise more than once? Does deregistering all callbacks at once seem 
counter-intuitive in that case if you want to show disinterest?

Another way out is to make ignore() cancel then() in a LIFO manner, probably 
also provide a ignoreAll(), which also gives a hint that ignore() only ignore 
one callback combination a time. But this just seems ugly.

> On Aug 3, 2015, at 11:49 PM, Boris Zbarsky <[email protected]> wrote:
> 
> On 8/2/15 8:43 PM, Glen Huang wrote:
>> You can think it as that each promise keeps a list of its child promises, 
>> when the same callback is passed to .ignore() it sets a flag on the 
>> corresponding child promise so that when itself resolves/rejects, it won't 
>> pass that state to that child promise
> 
> There seems to be a potential footgun here.  Say I call then() twice with the 
> same function.  Now I have two child promises.  If I now call ignore() with 
> that function, which of the child promises is ignored? Both?  Just one of 
> them?  Something else?
> 
> This situation doesn't _quite_ arise with add/removeEventListener, because 
> you can't addEventListener a given listener twice to the same event target.  
> So a removeEventListener can see at most one matching listener.
> 
> -Boris
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to