Futures

org.mbari.vars.migration.etc.sdk.Futures
object Futures

Concurrency utilities for simplifying the use of Futures for common cases.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Futures.type

Members list

Value members

Concrete methods

def join[T](f: => Future[T], timeout: Duration)(using ec: ExecutionContext): T
def safeRunSync[T](f: => Future[T], timeout: Duration)(using ec: ExecutionContext): Either[Throwable, T]

Run a Future and return the result or an Exception if the Future fails or does not complete within the timeout

Run a Future and return the result or an Exception if the Future fails or does not complete within the timeout

Type parameters

T

The type that the Future returns

Value parameters

f

A function that returns a Future

timeout

The maximum amount of time to wait for the Future to complete

Attributes

Returns

The result of the Future or an Exception

def safeTraverse[A, B](inputs: Seq[A])(f: A => Future[B])(using ec: ExecutionContext): Future[Seq[B]]

This is similar to Future.traverse but it will not fail if one of the Futures fails. Instead, it will return a sequence of results, omitting any that failed.

This is similar to Future.traverse but it will not fail if one of the Futures fails. Instead, it will return a sequence of results, omitting any that failed.

Type parameters

A

The type of the input elements

B

The type of the output elements

Value parameters

ec

The ExecutionContext to use for running the Futures

f

A function that takes an input of type A and returns a Future of type B

inputs

The sequence of inputs to traverse

Attributes

Returns

A Future that completes with a sequence of results of type B, omitting any that failed

Concrete fields

val DefaultTimeout: Duration

Extensions

Extensions

extension [T](f: Future[T])
def handleError(default: => T)(using ec: ExecutionContext): Future[T]
def join(timeout: Duration = ...)(using ec: ExecutionContext): T
def safeRunSync(timeout: Duration = ...)(using ec: ExecutionContext): Either[Throwable, T]