trait CompleteLastly extends AnyRef
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 } }
- Source
- CompleteLastly.scala
- Alphabetic
- By Inheritance
- CompleteLastly
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- 
      
      
      
        
      
    
      
        
        class
      
      
        ResultOfCompleteInvocation[T] extends AnyRef
      
      
      Class that provides the lastlymethod of thecomplete-lastlysyntax.
Value Members
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        !=(arg0: Any): Boolean
      
      
      - Definition Classes
- AnyRef → Any
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        ##(): Int
      
      
      - Definition Classes
- AnyRef → Any
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        ==(arg0: Any): Boolean
      
      
      - Definition Classes
- AnyRef → Any
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        asInstanceOf[T0]: T0
      
      
      - Definition Classes
- Any
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        clone(): AnyRef
      
      
      - Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        complete[T](completeBlock: ⇒ T)(implicit futuristic: Futuristic[T]): ResultOfCompleteInvocation[T]
      
      
      Registers a block of code that produces any "futuristic" type (any type Ffor which an implicitFuturistic[F]instance is implicitly available), returning an object that offers alastlymethod.Registers a block of code that produces any "futuristic" type (any type Ffor which an implicitFuturistic[F]instance is implicitly available), returning an object that offers alastlymethod.See the main documentation for trait CompleteLastlyfor more detail.- completeBlock
- cleanup code to execute whether the code passed to - completethrows an exception or succesfully returns a futuristic value.
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        eq(arg0: AnyRef): Boolean
      
      
      - Definition Classes
- AnyRef
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        equals(arg0: Any): Boolean
      
      
      - Definition Classes
- AnyRef → Any
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        finalize(): Unit
      
      
      - Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        getClass(): Class[_]
      
      
      - Definition Classes
- AnyRef → Any
- Annotations
- @native()
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        hashCode(): Int
      
      
      - Definition Classes
- AnyRef → Any
- Annotations
- @native()
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        isInstanceOf[T0]: Boolean
      
      
      - Definition Classes
- Any
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        ne(arg0: AnyRef): Boolean
      
      
      - Definition Classes
- AnyRef
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        notify(): Unit
      
      
      - Definition Classes
- AnyRef
- Annotations
- @native()
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        notifyAll(): Unit
      
      
      - Definition Classes
- AnyRef
- Annotations
- @native()
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        synchronized[T0](arg0: ⇒ T0): T0
      
      
      - Definition Classes
- AnyRef
 
- 
      
      
      
        
      
    
      
        
        def
      
      
        toString(): String
      
      
      - Definition Classes
- AnyRef → Any
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(): Unit
      
      
      - Definition Classes
- AnyRef
- Annotations
- @throws( ... )
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(arg0: Long, arg1: Int): Unit
      
      
      - Definition Classes
- AnyRef
- Annotations
- @throws( ... )
 
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(arg0: Long): Unit
      
      
      - Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )