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

io.fsq.common.scala.LazyLocal.scala Maven / Gradle / Ivy

The newest version!
// Copyright 2014 Foursquare Labs Inc. All Rights Reserved.

package io.fsq.common.scala

/**
  * Wrapper for lazy vals used within methods. lazy vals in methods synchronize
  * on the object instance, not in the scope of the method. Thus multiple threads
  * can block on evaluating the same lazy val in the method.
  *
  * ALWAYS USE THIS IF YOU WANT TO USE A lazy val IN A METHOD, e.g.
  *
  * 
  * def myLazilyEvaluatedFunc(..) = {..}
  * val l = LazyLocal(myLazilyEvaluatedFunc)
  * ...
  * l.value
  * 
  */
class LazyLocal[T](f: => T) {
  lazy val value: T = f
}

object LazyLocal {
  def apply[T](f: => T) = {
    new LazyLocal(f)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy