static O mapMethodLike vmBus_onMessage_weakRef(S msg, IVF1 onMessage) { Map map = vm_busListenersByMessage_live(); synchronized(map) { Set listeners = map.get(msg); if (listeners == null) map.put(msg, listeners = syncIdentityHashSet()); WeakRefVMBusListener listener = new(listeners, (_msg, arg) -> onMessage.get((A) arg)); // We're technically violating the one-synchronized-object-per-thread rule, // but it should be OK here. // TODO: remove empty sets from map listeners.add(listener); ret listener; } }