Created
November 6, 2011 14:08
-
-
Save heathermiller/1342922 to your computer and use it in GitHub Desktop.
Clojure to Scala, line by line
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
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