Libraryless. Click here for Pure Java version (2837L/17K).
1 | static <A> O mapMethodLike vmBus_onMessage_weakRef(S msg, IVF1<A> onMessage) { |
2 | Map<S, Set> map = vm_busListenersByMessage_live(); |
3 | synchronized(map) { |
4 | Set listeners = map.get(msg); |
5 | if (listeners == null) map.put(msg, listeners = syncIdentityHashSet()); |
6 | WeakRefVMBusListener listener = new(listeners, (_msg, arg) -> onMessage.get((A) arg)); |
7 | // We're technically violating the one-synchronized-object-per-thread rule, |
8 | // but it should be OK here. |
9 | // TODO: remove empty sets from map |
10 | listeners.add(listener); |
11 | ret listener; |
12 | } |
13 | } |
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: | 144 / 214 |
Version history: | 5 change(s) |
Referenced in: | [show references] |