This method constructs and returns a Future that will eventually hold the result of the execution of the supplied body The execution is performed by the specified Dispatcher.
Assures that any Future tasks initiated in the current thread will be executed asynchronously, including any tasks currently queued to be executed in the current thread.
Assures that any Future tasks initiated in the current thread will be executed asynchronously, including any tasks currently queued to be executed in the current thread. This is needed if the current task may block, causing delays in executing the remaining tasks which in some cases may cause a deadlock.
Note: Calling 'Future.await' will automatically trigger this method.
For example, in the following block of code the call to 'latch.open' might not be executed until after the call to 'latch.await', causing a deadlock. By adding 'Future.blocking()' the call to 'latch.open' will instead be dispatched separately from the current block, allowing it to be run in parallel:
val latch = new StandardLatch val future = Future() map { _ ⇒ Future.blocking() val nested = Future() nested foreach (_ ⇒ latch.open) latch.await }
Construct a completable channel
Create an empty Future with default timeout
Captures a block that will be transformed into 'Continuation Passing Style' using Scala's Delimited Continuations plugin.
Captures a block that will be transformed into 'Continuation Passing Style' using Scala's Delimited Continuations plugin.
Within the block, the result of a Future may be accessed by calling Future.apply. At that point execution is suspended with the rest of the block being stored in a continuation until the result of the Future is available. If an Exception is thrown while processing, it will be contained within the resulting Future.
This allows working with Futures in an imperative style without blocking for each result.
Completing a Future using 'CompletableFuture << Future' will also suspend execution until the value of the other Future is available.
The Delimited Continuations compiler plugin must be enabled in order to use this method.
Simple version of Futures.
Simple version of Futures.traverse. Transforms a Traversable[Future[A]] into a Future[Traversable[A]]. Useful for reducing many Futures into a single Future.
Transforms a Traversable[A] into a Future[Traversable[B]] using the provided Function A ⇒ Future[B].
Transforms a Traversable[A] into a Future[Traversable[B]] using the provided Function A ⇒ Future[B]. This is useful for performing a parallel map. For example, to apply a function to all items of a list in parallel:
val myFutureList = Futures.traverse(myList)(x ⇒ Future(myFunc(x)))