Skip to content

Instantly share code, notes, and snippets.

@pfn
Created January 27, 2012 20:30
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 pfn/1690765 to your computer and use it in GitHub Desktop.
Save pfn/1690765 to your computer and use it in GitHub Desktop.
listener queue with weak reference to anonymous functions
object E {
class O {
val listeners = new ArrayBuffer[E.H]
}
trait RO {
implicit val __ERO__ = new O
}
type H = PartialFunction[Any,Any]
}
abstract class E {
val queue = new ArrayBuffer[WeakReference[E.H]]
def add(e: E.H)(implicit o: E.O) {
o.listeners += e
queue += new WeakReference(e)
}
}
object U extends E
class M extends E.RO {
U add { case _ => () }
}
class N extends E.RO {
U add { case _ => () }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment