I am curious about how it is possible to return a future that contains a string value that is calculated in a separate thread and doesn't block the calling thread.
I have tried using a Runnable and passing it into a thread pool, but the overridden "run" method cannot return anything for the future, so that didn't work. I feel like I should be returning a future within my main future that gives back the string when it is done creating it, but I am not sure how. I want the outside future to immediately return.
def find(): Future[String] = {
Future {
val f = Future {
getString() // This future gets the string and doesn't block the outside future from immediately returning
}
val s = Await.result(f, Duration.Inf)
s
}
}
How could I get the inner future to calculate a value without blocking the outer future from immediately returning? Thanks!