Perhaps Future should have a static Future.cancelable method (similar to 
Proxy.revocable):

let { future, cancel } = Future.cancelable(function(resolver) { .. do future 
stuff .. });

You would still need a means to hook cancellation, possibly by replacing cancel 
to the caller:

function getJSON() {
  var xhr = new XMLHttpRequest();
  ...
  let { future, cancel } = Future.cancelable(...);
  return { future, cancel: function() { cancel(); xhr.abort(); } };
}

Ron

-----Original Message-----
From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On 
Behalf Of Brendan Eich
Sent: Tuesday, April 23, 2013 6:41 PM
To: Tab Atkins Jr.
Cc: es-discuss
Subject: Re: Futures

Tab Atkins Jr. wrote:
> On Sat, Apr 20, 2013 at 6:17 AM, Brendan Eich<bren...@mozilla.com>  wrote:
>> Tab Atkins Jr. wrote:
>>> It would be so nice if JS had multiple return values, so we could 
>>> let cancellable future-returning APIs just return a naked resolver 
>>> as their second value,
>> Hello, destructuring:
>>
>> let{  proxy, revoke}  = Proxy.revocable(target, handler);
>>
>>
>> from 
>> http://wiki.ecmascript.org/doku.php?id=strawman:revokable_proxies. Or use an 
>> array pattern if you prefer.
>>
>> JIT'ing VMs can optimize these pretty easily to avoid object allocation.
>
> Yeah, that's fine when you're explicitly invoking something that needs 
> to return two objects.

You didn't grok what I wrote. The object is erased, and the value(s) are 
returned to the caller depending on the pattern it uses.

> It's less fine when you have something like a hypothetical getJSON() 
> (future-returning XHR sugar), which can reasonably just return a 
> future, but which we also want to make cancellable.  Burdening *every* 
> call site

No, you can use a smaller pattern, e.g.

let { future } = getJSON();

instead of

let { future, cancel } = getJSON();

>   with the need to pull out the future from the returned object

No, see above.

>   isn't great.

HTH.

/be
_______________________________________________
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