I'm playing with the idea of building a FutureBuilder class to possibly simplify chaining Futures. In the process I'm trying to understand the consequences of using Await.
So If I have Mappers that go something like this F1(future1) -> F2 -> F3
F1: Builds object Foo
F2: Goes to the DB to add a value Bar to Foo
F3: Sends a message containing Foo to somewhere else
The problem I have is with F2, where typically I would create a Future to get Bar from the DB. In this case I'm already in a Future so it's easier to just an Await.result()
on the sub-future, so that I can immediately add it to Foo and pass it on to F3.
Is there a problem with that? since I'm it's alreayd in a future am I locking an additional thread by waiting?
OR is there a different pattern entirely I should do? Keep in mind I want to be able to keep going so have the Foo object passed on in the mapper so that I can easily add F4,5,6,etc. I know I could also move F3 into F2 and map with the DB request but that would also mean I have to move F4,5,6,etc. with it?