Skip to content

Instantly share code, notes, and snippets.

@heathermiller
Created November 6, 2011 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heathermiller/1342922 to your computer and use it in GitHub Desktop.
Save heathermiller/1342922 to your computer and use it in GitHub Desktop.
Clojure to Scala, line by line
def slow = Thread.sleep(700)
def fast = Thread.sleep(100)
def threadDeliver[T](fun: => T, prom: SyncVar[T]) =
actor { prom set fun }
def main[T](a: => T, aw: Long, b: => T, overall: Long, default: T): T = {
val p = new SyncVar[T]
threadDeliver(a, p)
p.get(aw) match {
case Some(r) => r
case None =>
threadDeliver(b, p)
p.get(overall - aw) match {
case None => default
case Some(r) => r
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment