Sounds good to me. On Sat, Apr 14, 2018 at 9:55 AM, Ken Krugler <kkrugler_li...@transpac.com> wrote:
> Hi Ted, > > Thanks - yes regarding renaming the variable, and changing the type. > > The other issue is that most clients return a Future, not a > CompletableFuture. > > So should I do the bit of extra code to show using a CompletableFuture > with a Future? > > — Ken > > > On Apr 14, 2018, at 9:13 AM, Ted Yu <yuzhih...@gmail.com> wrote: > > > > bq. resultFuture.thenAccept( (String result) -> { > > > > I think the type of variable for the above call should be > CompletableFuture. > > Meaning, the variable currently named resultFuture should be renamed so > > that the intention is clearer. > > > > bq. resultFuture.complete(Collections.singleton(new > > Tuple2<>(str, result))); > > > > Looking at existing code in unit tests, the complete() call is on the > > parameter. > > > > Cheers > > > > On Sat, Apr 14, 2018 at 8:34 AM, Ken Krugler < > kkrugler_li...@transpac.com> > > wrote: > > > >> Hi devs, > >> > >> https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/stream/ > >> operators/asyncio.html <https://ci.apache.org/ > projects/flink/flink-docs- > >> release-1.4/dev/stream/operators/asyncio.html> > >> > >> Has this example of asyncInvoke: > >> > >>> @Override > >>> public void asyncInvoke(final String str, final > >> ResultFuture<Tuple2<String, String>> resultFuture) throws Exception { > >>> > >>> // issue the asynchronous request, receive a future for result > >>> Future<String> resultFuture = client.query(str); > >>> > >>> // set the callback to be executed once the request by the > >> client is complete > >>> // the callback simply forwards the result to the result future > >>> resultFuture.thenAccept( (String result) -> { > >>> > >>> resultFuture.complete(Collections.singleton(new > >> Tuple2<>(str, result))); > >>> > >>> }); > >>> } > >> > >> 1. there’s a resultFuture parameter, and a resultFuture variable. > >> > >> 2. resultFuture.thenAccept() is a method available for > CompletableFuture < > >> https://docs.oracle.com/javase/8/docs/api/java/util/ > >> concurrent/CompletableFuture.html>, not Future. > >> > >> I can fix this up, but I’m wondering what you think the code should do, > >> assuming there’s a typical client that returns a Future vs. a > >> CompletableFuture. > >> > >> e.g. I could use CompletableFuture.supplyAsync(new Supplier<String>() > { } > >> with a get that calls the Future’s get(). > >> > >> Thanks, > >> > >> — Ken > >> > >> -------------------------------------------- > >> http://about.me/kkrugler > >> +1 530-210-6378 > >> > >> > > -------------------------------------------- > http://about.me/kkrugler > +1 530-210-6378 > >