Class that provides the lastly
method of the complete
-lastly
syntax.
Class that provides the lastly
method of the complete
-lastly
syntax.
Registers a block of code that produces any "futuristic" type (any type F
for which
an implicit Futuristic[F]
instance is implicitly available), returning
an object that offers a lastly
method.
Registers a block of code that produces any "futuristic" type (any type F
for which
an implicit Futuristic[F]
instance is implicitly available), returning
an object that offers a lastly
method.
See the main documentation for trait CompleteLastly
for more detail.
cleanup code to execute whether the code passed to complete
throws an exception or succesfully returns a futuristic value.
Trait that provides a
complete
-lastly
construct, which ensures cleanup code inlastly
is executed whether the code passed tocomplete
completes abruptly with an exception or successfully results in aFuture
,FutureOutcome
, or other type with an implicitFuturistic
instance.This trait is mixed into ScalaTest's async testing styles, to make it easy to ensure cleanup code will execute whether code that produces a "futuristic" value (any type
F
for which aFuturistic[F]
instance is implicitly available). ScalaTest provides implicitFuturistic
instances forFuture[T]
for any typeT
andFutureOutcome
.If the future-producing code passed to
complete
throws an exception, the cleanup code passed tolastly
will be executed immediately, and the same exception will be rethrown, unless the code passed tolastly
also completes abruptly with an exception. In that case,complete
-lastly
will complete abruptly with the exception thrown by the code passed tolastly
(this mimics the behavior offinally
).Otherwise, if the code passed to
complete
successfully returns aFuture
(or other "futuristic" type),complete
-lastly
will register the cleanup code to be performed once the future completes and return a new future that will complete once the original future completes and the subsequent cleanup code has completed execution. The future returned bycomplete
-lastly
will have the same result as the original future passed tocomplete
, unless the cleanup code throws an exception. If the cleanup code passed tolastly
throws an exception, the future returned bylastly
will fail with that exception.The
complete
-lastly
syntax is intended to be used to ensure cleanup code is executed in async testing styles liketry
-finally
is used in traditional testing styles. Here's an example ofcomplete
-lastly
used inwithFixture
in an async testing style: