Skip to content

Instantly share code, notes, and snippets.

@tpolecat
Created February 2, 2013 04:23
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 tpolecat/4696104 to your computer and use it in GitHub Desktop.
Save tpolecat/4696104 to your computer and use it in GitHub Desktop.
class Box[A] {
private var waiters = Queue[A => Unit]()
def watch(f:A => Unit) = waiters = waiters :+ f
def put(a:A) = waiters.foreach(_(a))
}
val b = new Box[String]
for (i <- 1 to 5)
b.watch(s => println(s + " " + i))
b.put("foo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment