Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

java - How can I make A future of future into one future object?

Env: Akka 2.1, scala version 2.10.M6, JDK 1.7,u5

Now is my problem: I have:

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

now in first line, I have a future of Future of object, is there any way to convert it into a Future while not blocking my current thread?

Is there any method in akka? As far as I checked, I havn't found any yet... First time to have a post....Sry for bad format and organize... :~P

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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; }
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...