Created
January 19, 2014 15:18
-
-
Save mrogaski/8506237 to your computer and use it in GitHub Desktop.
ConcurrentHashMap getOrElseProduce()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.dispatch.Future._ | |
def getOrElseProduce(key: K, producer: => V): Future[V] = { | |
val f = empty[V]() | |
putIfAbsent(key, f) match { | |
case null => f completeWithResult producer | |
case value => value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment