Future

gears.async.Future
See theFuture companion trait
object Future

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Future.type

Members list

Type members

Classlikes

class Collector[T](futures: Future[T]*)

Collects a list of futures into a channel of futures, arriving as they finish.

Collects a list of futures into a channel of futures, arriving as they finish.

Attributes

See also

Future.awaitAll and Future.awaitFirst for simple usage of the collectors to get all results or the first succeeding one.

Example
// Sleep sort
val futs = numbers.map(i => Future(sleep(i.millis)))
val collector = Collector(futs*)
val output = mutable.ArrayBuffer[Int]()
for i <- 1 to futs.size:
 output += collector.results.read().await
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class MutableCollector[T]
class MutableCollector[T](futures: Future[T]*) extends Collector[T]

Like Collector, but exposes the ability to add futures after creation.

Like Collector, but exposes the ability to add futures after creation.

Attributes

Supertypes
class Collector[T]
class Object
trait Matchable
class Any
object Promise

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Promise.type
trait Promise[T] extends Future[T]

A promise is a Future that is be completed manually via the complete method.

A promise is a Future that is be completed manually via the complete method.

Attributes

See also

Promise$.apply to create a new, empty promise.

Future.withResolver to create a passive Future from callback-style asynchronous calls.

Companion
object
Supertypes
trait Future[T]
trait Cancellable
class OriginalSource[Try[T]]
trait Source[Try[T]]
class Object
trait Matchable
class Any
Show all
trait Resolver[-T]

The group of handlers to be used in withResolver. As a Future is completed only once, only one of resolve/reject/complete may be used and only once.

The group of handlers to be used in withResolver. As a Future is completed only once, only one of resolve/reject/complete may be used and only once.

Attributes

Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

def apply[T](body: Spawn ?=> T)(using async: Async, spawnable: Spawn & async.type): Future[T]

Create a future that asynchronously executes body that wraps its execution in a scala.util.Try. The returned future is linked to the given Async.Spawn scope by default, i.e. it is cancelled when this scope ends.

Create a future that asynchronously executes body that wraps its execution in a scala.util.Try. The returned future is linked to the given Async.Spawn scope by default, i.e. it is cancelled when this scope ends.

Attributes

inline def completed[T](result: Try[T]): Future[T]

An alias to now.

An alias to now.

Attributes

def now[T](result: Try[T]): Future[T]

A future that is immediately completed with the given result.

A future that is immediately completed with the given result.

Attributes

inline def rejected(exception: Throwable): Future[Nothing]

A future that immediately rejects with the given exception. Similar to Future.now(Failure(exception)).

A future that immediately rejects with the given exception. Similar to Future.now(Failure(exception)).

Attributes

inline def resolved[T](result: T): Future[T]

A future that immediately resolves with the given result. Similar to Future.now(Success(result)).

A future that immediately resolves with the given result. Similar to Future.now(Success(result)).

Attributes

def withResolver[T](body: (Resolver[T]) => Unit): Future[T]

Create a promise that may be completed asynchronously using external means.

Create a promise that may be completed asynchronously using external means.

The body is run synchronously on the callers thread to setup an external asynchronous operation whose success/failure it communicates using the Resolver to complete the future.

If the external operation supports cancellation, the body can register one handler using Resolver.onCancel.

Attributes

Extensions

Extensions

extension [T](f1: Future[T])
def or(f2: Future[T]): Future[T]

Alternative parallel composition of this task with other task. If either task succeeds, succeed with the success that was returned first. Otherwise, fail with the failure that was returned last.

Alternative parallel composition of this task with other task. If either task succeeds, succeed with the success that was returned first. Otherwise, fail with the failure that was returned last.

Attributes

See also

orWithCancel for an alternative version where the slower future is cancelled.

inline def orImpl(inline withCancel: Boolean)(f2: Future[T]): Future[T]
def orWithCancel(f2: Future[T]): Future[T]

Like or but the slower future is cancelled. If either task succeeds, succeed with the success that was returned first and the other is cancelled. Otherwise, fail with the failure that was returned last.

Like or but the slower future is cancelled. If either task succeeds, succeed with the success that was returned first and the other is cancelled. Otherwise, fail with the failure that was returned last.

Attributes

def zip[U](f2: Future[U]): Future[(T, U)]

Parallel composition of two futures. If both futures succeed, succeed with their values in a pair. Otherwise, fail with the failure that was returned first.

Parallel composition of two futures. If both futures succeed, succeed with their values in a pair. Otherwise, fail with the failure that was returned first.

Attributes

extension [T](fs: Seq[Future[T]])
def awaitAll(using Async): Seq[T]

.await for all futures in the sequence, returns the results in a sequence, or throws if any futures fail.

.await for all futures in the sequence, returns the results in a sequence, or throws if any futures fail.

Attributes

def awaitAllOrCancel(using Async): Seq[T]

Like awaitAll, but cancels all futures as soon as one of them fails.

Like awaitAll, but cancels all futures as soon as one of them fails.

Attributes

def awaitFirst(using Async): T

Race all futures, returning the first successful value. Throws the last exception received, if everything fails.

Race all futures, returning the first successful value. Throws the last exception received, if everything fails.

Attributes

def awaitFirstWithCancel(using Async): T

Like awaitFirst, but cancels all other futures as soon as the first future succeeds.

Like awaitFirst, but cancels all other futures as soon as the first future succeeds.

Attributes