CompleteLastly

Trait that provides a complete-lastly construct, which ensures cleanup code in lastly is executed whether the code passed to complete completes abruptly with an exception or successfully results in a Future, FutureOutcome, or other type with an implicit Futuristic 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 a Futuristic[F] instance is implicitly available). ScalaTest provides implicit Futuristic instances for Future[T] for any type T and FutureOutcome.

If the future-producing code passed to complete throws an exception, the cleanup code passed to lastly will be executed immediately, and the same exception will be rethrown, unless the code passed to lastly also completes abruptly with an exception. In that case, complete-lastly will complete abruptly with the exception thrown by the code passed to lastly (this mimics the behavior of finally).

Otherwise, if the code passed to complete successfully returns a Future (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 by complete-lastly will have the same result as the original future passed to complete, unless the cleanup code throws an exception. If the cleanup code passed to lastly throws an exception, the future returned by lastly will fail with that exception.

The complete-lastly syntax is intended to be used to ensure cleanup code is executed in async testing styles like try-finally is used in traditional testing styles. Here's an example of complete-lastly used in withFixture in an async testing style:

// Your implementation
override def withFixture(test: NoArgAsyncTest) = {

 // Perform setup here

 complete {
   super.withFixture(test) // Invoke the test function
 } lastly {
   // Perform cleanup here
 }
}
Companion:
object
class Object
trait Matchable
class Any

Type members

Classlikes

class ResultOfCompleteInvocation[T](futuristicBlock: => T, futuristic: Futuristic[T])

Class that provides the lastly method of the complete-lastly syntax.

Class that provides the lastly method of the complete-lastly syntax.

Value parameters:
futuristic

the futuristic typeclass instance

futuristicBlock

a by-name that produces a futuristic type

Value members

Concrete methods

def complete[T](completeBlock: => T)(implicit futuristic: Futuristic[T]): ResultOfCompleteInvocation[T]

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.

Value parameters:
completeBlock

cleanup code to execute whether the code passed to complete throws an exception or succesfully returns a futuristic value.