Java – how to make the future the object of the future?

Env: akka 2.1, Scala version 2.10 M6,JDK 1.7,u5

Now it's my question: I have:

future1 = Futures.future(new Callable<Future<object>>(){...});
future2 = ? extends Object;
Future.sequence(future1,future2).onComplete(...)

Now on the front line, I have future objects. Is there any way to convert them into the future without blocking my current thread?

Is there any way in akka? As far as I know, I haven't found... A position for the first time Dirty format and organization...: ~ p

Solution

Short answer (English): flatmap dat sh! t

Shorter answer (Scala):

flatMap(identity)

Shortest answer (Scala 2.12):

flatten

Long answer (Java):

flatMap(new Mapper<Future<X>>,Future<X>>() {
  @Override public Future<X> apply(final Future<X> f) { return f; }
})
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>