This was assuming an API like addEventListener/removeEventListener, not the
standard DOM setTimeout/clearTimeout, sorry for the confusion.


On 12 August 2015 at 15:46, Salvador de la Puente González <
sa...@unoyunodiez.com> wrote:

> AFAIK, this wont work because what clearTimeout() is actually expecting is
> the id returned by setTimeout().
> El 12/8/2015 16:00, "Nick Krempel" <ndkrem...@google.com> escribió:
>
>> On 12 August 2015 at 02:56, Isiah Meadows <isiahmead...@gmail.com> wrote:
>>
>>> ```js
>>>
>>> let p = new Promise((resolve, reject) =>
>>>   setTimeout((x => () => x(x))(handler => {
>>>     onNotNeeded(() => clearTimeout(handler));
>>>
>>>     // `return` is to take advantage of TCO
>>>     return doSomethingAsync(err => {
>>>       if (err != null) return reject(err)
>>>       else return resolve();
>>>     });
>>>   }));
>>> ```
>>>
>> This doesn't work as the function passed to clearTimeout does not === the
>> function passed to setTimeout.
>>
>> In fact, they're not even behaviorally equal as the function passed to
>> setTimeout is expecting no parameters and the function passed to
>> clearTimeout is expecting one parameter - i.e. this is not even correct in
>> lambda calculus.
>>
>> A lambda-calculus-correct version could be:
>>
>> ```
>> setTimeout((x=>(y=>()=>x(y(y)))(y=>()=>x(y(y))))(handler => {...}));
>> ```
>>
>> But this would still suffer from the object identity problem mentioned
>> above. A final JS-correct version could be:
>>
>> ```
>> setTimeout((x => {const y = () => x(y); return y;})(handler => {...}));
>> ```
>>
>> Nick
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to