Using

object Using
Companion
class
class Object
trait Matchable
class Any

Type members

Classlikes

trait ScopeExitHandler extends AutoCloseable

Value members

Concrete methods

def apply[R <: AutoCloseable](r: => R)(implicit dummyImplicit: DummyImplicit): Using[R]

Returns a Using keyword to execute a ScopeExitHandler when exiting the nearest enclosing scope that is annotated as @reset, (or the nearest enclosing function if compilerplugins.ResetEverywhere is enabled).

Returns a Using keyword to execute a ScopeExitHandler when exiting the nearest enclosing scope that is annotated as @reset, (or the nearest enclosing function if compilerplugins.ResetEverywhere is enabled).

Note

This method is similar to apply, except the parameter type is changed from a generic R to the SAM type ScopeExitHandler, which allows for function literal expressions in Scala 2.12+ or Scala 2.11 with -Xexperimental compiler option.

Example

The following function will perform n *= 2 after n += 20:

        import scala.concurrent.Future
        import com.thoughtworks.dsl.keywords.Using.scopeExit
        import com.thoughtworks.dsl.bangnotation._
        var n = 1
        def multiplicationAfterAddition = *[Future] {
          !scopeExit { () =>
            n *= 2
          }
          n += 20
        }
    Therefore, the final value of `n` should be `(1 + 20) * 2 = 42`.
        multiplicationAfterAddition.map { _ =>
          n should be(42)
        }

Givens

Givens

given AsKeyword_R_Using_R: From => Keyword
given IsKeyword_Using_R[R <: AutoCloseable]: IsKeyword[Using[R], R]

Implicits

Implicits

implicit
def continuationUsingDsl[Domain, Value, R <: AutoCloseable](implicit tryFinally: TryFinally[Value, Domain, Domain, Domain]): Dsl[Using[R], Domain !! Value, R]
implicit
def scalaFutureUsingDsl[R <: AutoCloseable, A](implicit executionContext: ExecutionContext): Dsl[Using[R], Future[A], R]