Libraryless. Click here for Pure Java version (2837L/17K).
static <A> O mapMethodLike vmBus_onMessage_weakRef(S msg, IVF1<A> onMessage) { Map<S, Set> 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; } }
Began life as a copy of #1018419
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031570 |
Snippet name: | vmBus_onMessage_weakRef - must keep a reference to the returned listener otherwise it is removed after GC |
Eternal ID of this version: | #1031570/6 |
Text MD5: | 38be466b984692da9162b37499d74cec |
Transpilation MD5: | d28150d2647a1ce4e827db1161dbe4a7 |
Author: | stefan |
Category: | javax / vm |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-22 03:52:51 |
Source code size: | 572 bytes / 13 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 145 / 215 |
Version history: | 5 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1031573 - vmBus_onMessage_withLivelinessCheck - performs a custom liveliness check before every invocation and drops listener if check fails |