![scala future scala future](https://i.ytimg.com/vi/aAhGz9KO5ZA/maxresdefault.jpg)
The Akka Streams API also uses the Scala Future in all places.
#Scala future code#
Both the Akka Toolkit and the Play Framework source code use Scala Futures extensively. Unless you are awaiting the result you are mapping this Future Option Book. The Scala Future API in the Akka Toolkit. But if it is important to block until the answer is available, then use (preferably wrapped in a Try to catch errors). Telemetry for Scala Futures needs to be explicitly enabled, and Futures need to be explicitly named in code, using a naming API provided by the Cinnamon Scala module. Normally you'd return Future Boolean and thus defer the requirement to have the answer for as long as possible. Note that an onComplete callback by itself, or Future operations such as foreach, do not create new Futures and only record the callback metrics. Answer (1 of 37): TL DR: Learning Scala and the mix of OOP and FP that comes with it, will not only help you write better code, but it will also enable you to solve the more difficult problems at a higher level of abstraction. The way that metrics are recorded for the Future and callback are shown in this diagram: The callback will then run as determined by the execution context, calling the map function and completing the Future with the result. When the original Future has completed, the map callback is scheduled for execution. When map is called, a new Future is created for the result of the map function and an onComplete callback is added to the original Future. To illustrate how future metrics are recorded, consider a map operation on a Future. Processing time (recorder) - the time that Futures/callbacks take to run. Processed futures (rate) - the rate of Futures/callbacks being processed (marked when the Future/callback has finished running). Scheduling time (recorder) - the time that Futures/callbacks are in scheduling (in execution context queues waiting to run). Scheduled futures (recorder) - the number of Futures currently scheduled (includes both Future runnables and Future callbacks).
![scala future scala future](https://image.slidesharecdn.com/futurepromises-150724181714-lva1-app6891/95/scala-future-promises-24-1024.jpg)
The following metrics are recorded for named Scala Futures, type of metric in parentheses:Ĭreated futures (rate) - the rate of Futures being created (for a given name).Ĭompleting time (recorder) - the time from creation to completing the underlying Promise for this Future. This quence() function converts a list of Futures into a single Future that means collections of Futures into a single Future. An ActorSystem needs to be initialized before Scala Future telemetry can be reported. Scala quence() When we have a sequence of Futures, or a list of Futures, or a collection of Futures, we should use one of the Future combinator APIs, quence(), to deal with this scenario. Scala Future instrumentation is currently only supported in conjunction with Actor instrumentation, as the Scala Future telemetry uses the metric backends as configured for an ActorSystem.