Future.always
is a way to lift a normal value T
to a Future[T]
value. This lifting pattern is something you will see often in functional programming, so remember it well!
To make its usefulness more apparent - imagine that your API method should either call some Web service or look in the cached responses to see if the Web service was already queried with that request. In the first case you have to return a future Future[String]
of a response, and in the second you need to return a response String
right away from your cache. Future.always
can help you solve this tricky type situation.