threerings/react — pull request #1 by groves (2013-04-10 00:38:24+00:00)
Title: Add a connection that only weakly references its listener

If I remember correctly, we didn't add a weak referenced version of connections back in the day because GWT doesn't support WeakReference. I'm now using react on Android, which does support them. I'd very much like to be able to add listeners without needing to worry about disconnecting them when I'm done.

This just implements weak connections for Values. Before completing the implementation for the other Reactor subclasses I wanted to check if a change like this would be accepted upstream and if it needed to be done differently to keep from breaking GWT. Yea? Nay? Maybe?

Also, this doesn't handle priority properly if a weak listener has a non-zero priority. If another listener with a non-zero priority is connected while that listener is still in the Cons list but garbage collected, it'll look like the weak listener has a priority of zero.

However, I think priority is broken in general. It's a method on the listener, so it can change after the listener has been added. The Reactor can't detect that that priority has changed though, so it doesn't resort its list. Seems like the priority should be on the Connection and not the Listener, which would fix the weak listener case as well.