Timed

object Timed

Companion object for Timed typeclass that offers three implicit providers: one for FutureOutcome, one for Future of any type, and one for any other type.

The details are in the documentation for the implicit providers themselves (methods timed, timedFutureOf, and timedFutureOutcome), but in short if a time limit is exceeded:

  • if the type T in Timed[T] is FutureOutcome the FutureOutcome returned by timeoutAfter will result in either Failed or Canceled

  • if the type is Future[U], the Future[U] returned by timeoutAfter will fail with either a TestFailedDueToTimeoutException or a TestCanceledException.

  • otherwise, the timeoutAfter method will itself complete abruptly with either TestFailedDueToTimeoutException or TestCanceledException.

Companion:
class
class Object
trait Matchable
class Any
Timed.type

Implicits

Implicits

implicit def timed[T]: Timed[T]

Implicit method that provides Timed implementation for any T.

Implicit method that provides Timed implementation for any T.

If the function completes before the timeout expires:

  • If the function returns normally, this method will return normally.

  • If the function completes abruptly with an exception, this method will complete abruptly with that same exception.

If the function completes after the timeout expires:

  • If the function returns normally, this method will complete abruptly with a StackDepthException created from exceptionFun.

  • If the function completes abruptly with an exception, this method will complete abruptly with a StackDepthException created from exceptionFun that includes the exception thrown by the function as its cause.

This implementation will start a timer that when the time limit is exceeded while the passed in function f is still running, it will attempt to call the passed in Signaler to signal/interrupt the running function f.

implicit def timedFutureOf[T](implicit executionContext: ExecutionContext): Timed[Future[T]]

Implicit method that provides Timed implementation for any Future[T].

Implicit method that provides Timed implementation for any Future[T].

If the asynchronous function completes before the timeout expires:

  • If the function returns normally, the Future will be completed with the return value of the function.

  • If the function completes abruptly with an exception, this method will complete the Future with that same exception.

If the asynchronous function completes after the timeout expires:

  • If the function returns normally, this method will complete the Future with a StackDepthException created from exceptionFun.

  • If the function completes abruptly with an exception, this method will complete the Future with a StackDepthException created from exceptionFun that includes the exception thrown by the function as its cause.

This implementation will start a timer that when the time limit is exceeded while the passed in asynchronous function f is still running, it will attempt to call the passed in Signaler to signal/interrupt the running function f.

implicit def timedFutureOutcome(implicit executionContext: ExecutionContext): Timed[FutureOutcome]

Implicit method that provides Timed implementation for FutureOutcome.

Implicit method that provides Timed implementation for FutureOutcome.

If the asynchronous function completes before the timeout expires:

  • If the function returns normally, the FutureOutcome will be completed with the Outcome returned from the function.

  • If the function completes abruptly with an TestPendingException, this method will complete the FutureOutcome with Pending.

  • If the function completes abruptly with an TestCanceledException, this method will complete the FutureOutcome with Canceled that contains the thrown exception.

  • If the function completes abruptly with a run-aborting exception, this method will complete the FutureOutcome with Failed that contains the thrown exception.

  • If the function completes abruptly with a non-run-aborting exception, this method will fail the FutureOutcome with ExecutionException that contains the thrown exception.

If the asynchronous function completes after the timeout expires:

  • If the function returns normally, this method will complete the FutureOutcome with a Outcome that's mapped from the exception thrown from exceptionFun.

  • If the function completes abruptly with an exception, this method will complete the FutureOutcome with Outcome that's mapped from the exception thrown from exceptionFun that includes the exception thrown by the function as its cause.

This implementation will start a timer that when the time limit is exceeded while the passed in asynchronous function f is still running, it will attempt to call the passed in Signaler to signal/interrupt the running function f.