Closed jonathanhefner closed 4 years ago
@headius Does this look all right to you? I decided to forgo clearing dead WeakRef
s in Listen.to
because it would require using Mutex
instead of a simple Queue
to stay thread-safe. I can make that change if you prefer. However, if someone were to create so many listeners that dead WeakRef
s could become a problem, they might prefer using Listener.new
instead (since it will have less overhead).
The
@listeners
variable holds a reference to eachListener
instance created byListen.to
and can only be cleared by callingListen.stop
. This can preventListener
instances from being garbage collected if they are abandoned beforeListen.stop
is called.This commit wraps
Listener
instances inWeakRef
before adding them to@listeners
, to allow them to be garbage collected.Partially addresses #476.