How to change the timeout in folded futures?

In the example from the akka 1.1 documentation for compiling futures , I wonder how to programmatically set the timeout of the generated future. I know that I can set the global timeout in akka.conf, but I want to do this only for this piece of code.

Sample code is as follows

val f1 = actor1 !!! msg1 val f2 = actor2 !!! msg2 val f3 = for { a: Int <- f1 b: Int <- f2 c: String <- actor3 !!! (a + b) } yield c val result = f3.get() 

Is it correct that in this example, akka creates a total of four futures?

  • One for each message is sent to actor1, 2 and 3
  • One to wrap these three futures

It is easy to change timeouts in the first case, for example.

 val f1 = actor1 !!! (msg1, 15000) // sets timeout to 15 seconds 

but how can I set a timeout for future packaging? Any ideas?

+6
source share
1 answer

In fact, there would be 6 futures, which I consider 3 of the actors you received and 1 for each flatMap / map method.

The timeout for the 3rd actor futures is set in the same way as you stated, but the futures for frames 3 inherit the timeout from the future on the right side of each section for understanding. However, the returned future will use the timeout of the first future for understanding.

For Akka 2.0, this will change to indicate an implicit timeout until problems occur during testing.

+6
source

Source: https://habr.com/ru/post/892703/


All Articles