
org.scalatra.util.package.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalatra_2.9.0 Show documentation
Show all versions of scalatra_2.9.0 Show documentation
The core Scalatra framework
The newest version!
package org.scalatra
package object util {
/**
* Executes a block with a closeable resource, and closes it after the block runs
*
* @tparam A the return type of the block
* @tparam B the closeable resource type
* @param closeable the closeable resource
* @param f the block
*/
def using[A, B <: { def close(): Unit }](closeable: B)(f: B => A) {
try {
f(closeable)
}
finally {
if (closeable != null)
closeable.close()
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy