All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skinny.util.LoanPattern.scala Maven / Gradle / Ivy

package skinny.util

import scala.language.reflectiveCalls

/**
 * Loan pattern.
 */
object LoanPattern {

  type Closable = { def close() }

  /**
   * Closes the resource finally.
   */
  def using[R <: Closable, A](resource: R)(f: R => A): A = {
    try {
      f(resource)
    } finally {
      try {
        resource.close()
      } catch {
        case scala.util.control.NonFatal(_) =>
      }
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy