Libraryless. Click here for Pure Java version (2821L/17K).
1 | // The lazy man's method of registering a VM bus listener |
2 | // You only need to keep a reference around but not to close() anything |
3 | // OTOH you depend on the GC for cleaning up your listener |
4 | // structures which is not so good |
5 | sclass WeakRefVMBusListener extends WeakReference implements IF2<S, O, O> { |
6 | Set listeners; // where we were added |
7 | |
8 | *(Set *listeners, O listener) { super(listener); } |
9 | *(Set *listeners, IVF2<S, O> listener) { super(listener); } |
10 | |
11 | public O get(S msg, O arg) { |
12 | O listener = get(); |
13 | if (listener == null) { |
14 | ifdef WeakRefVMBusListener_debug |
15 | print WeakRefVMBusListener_debug("Removing VM bus listener"); |
16 | endifdef |
17 | remove(listeners, this); |
18 | null; |
19 | } |
20 | ret callF(listener, msg, arg); |
21 | } |
22 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031569 |
Snippet name: | WeakRefVMBusListener |
Eternal ID of this version: | #1031569/9 |
Text MD5: | 59f6e889cc319db0dd2c04c424758ba6 |
Transpilation MD5: | b86b671393602b377763c308354b43db |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-22 04:04:35 |
Source code size: | 778 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 221 / 397 |
Version history: | 8 change(s) |
Referenced in: | [show references] |