Created
January 27, 2012 20:30
-
-
Save pfn/1690765 to your computer and use it in GitHub Desktop.
listener queue with weak reference to anonymous functions
This file contains 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
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