Re: [guava] New Empty ListenableFuture

1,142 views
Skip to first unread message

Louis Wasserman

unread,
Jan 14, 2013, 4:27:41 PM1/14/13
to kramer.n...@gmail.com, guava-...@googlegroups.com

Sounds like you want http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/SettableFuture.html probably?

On Jan 14, 2013 1:22 PM, <kramer.n...@gmail.com> wrote:
Hey guys,

I have an asynchronous apit which I am trying to "mock" for testing purposes.

I plan to call

Futures.addCallback(Future, Callback) in order to add a callback, but I need an empty ListenableFuture in order to call that.

Perhaps I am mis-understanding the future object.  If so, please enlighten me.

--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")

kramer.n...@gmail.com

unread,
Jan 14, 2013, 4:47:29 PM1/14/13
to guava-...@googlegroups.com, kramer.n...@gmail.com
That might be what I want.

Please forgive my ignorance, but would I instantiate a SettableFuture thusly?

ListenableFuture<ClientResponse> result = SettableFuture<ClientResponse>.create();

Because that line gives the compile error: illegal start of expression

David Beaumont

unread,
Jan 14, 2013, 4:53:07 PM1/14/13
to kramer.n...@gmail.com, guava-discuss
On 14 January 2013 22:47, <kramer.n...@gmail.com> wrote:
> ListenableFuture<ClientResponse> result =
> SettableFuture<ClientResponse>.create();

I think you want:
ListenableFuture<ClientResponse> result = SettableFuture.create();

The static method captures the type so you do not need to specify it.
I am guessing Eclipse auto-filled the type for you ... it does that a
lot.

David

--
David Beaumont :: Îñţérñåţîöñåļîžåţîờñ Libraries :: Google
Google Switzerland GmbH., Brandschenkestrasse 110, CH-8002, Zürich - Switzerland
Tel +41 44 668 1800 :: Fax +41 44 668 1818

Louis Wasserman

unread,
Jan 14, 2013, 4:53:07 PM1/14/13
to kramer.n...@gmail.com, guava-...@googlegroups.com
You just need to call SettableFuture.create() -- you wouldn't need any generics, and if you did want to provide specific generics, they'd go after the period, not before.
--
Louis Wasserman
Reply all
Reply to author
Forward
0 new messages