[concurrency-interest] ImmediateFuture

Ben Manes ben_manes at yahoo.com
Wed Jun 17 15:55:17 EDT 2009


And I am yet another doing this.  I have an "eager" future with immediately computes/takes the value and a "lazy" future which computes it on the first invocation.  The eager future is really handy (e.g. a memoizer-based map) and the lazy future to pass up a lower-level futures with some attached post processing logic (e.g. asynchronous memcached call where deserialize is thepost-processing step).




________________________________
From: Kevin Bourrillion <kevinb at google.com>
To: Jim Andreou <jim.andreou at gmail.com>
Cc: Joe Kearney <Joe.Kearney at morganstanley.com>; concurrency-interest at cs.oswego.edu
Sent: Wednesday, June 17, 2009 9:14:38 AM
Subject: Re: [concurrency-interest] ImmediateFuture

Our own Futures.immediateFuture() utility is fairly popular as well, and not only in test code.  For example, sometimes an interface wants to only require a Future to be returned, but an implementation happens to already have the value.




On Wed, Jun 17, 2009 at 8:38 AM, Jim Andreou <jim.andreou at gmail.com> wrote:

One could use something like this, to avoid introducing a new type:

private static final Runnable emptyRunnable = new Runnable() { public void run() { } };
public static <T> Future<T> futureFor(T value) { 
    return new FutureTask<T>(emptyRunnable, value);
}

2009/6/17 Joe Kearney <Joe.Kearney at morganstanley.com>


I had to write one of these, I called it ConstantFuture. Fairly trivial implementation, but would be nice to have on hand.


2009/6/17 Mark Thornton <mthornton at optrak.co.uk>

For test purposes I created an ImmediateFuture class which implements Future but where the value already exists. Am I the only person to have found the need to do this or should something like it be considered for more general use?


Mark Thornton

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest




-- 
Kevin Bourrillion @ Google
internal:  http://go/javalibraries
google-collections.googlecode.com
google-guice.googlecode.com


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090617/10b0b2b4/attachment-0001.html>


More information about the Concurrency-interest mailing list