Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1031573 // vmBus_onMessage_withLivelinessCheck - performs a custom liveliness check before every invocation and drops listener if check fails

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2894L/17K).

static <A> O vmBus_onMessage_withLivelinessCheck(bool verbose default false, IF0<Bool> livelinessCheck, S msg, IVF1<A> onMessage) {
  // Do this BEFORE synchronizing on the map!
  VMBusListenerWithLivelinessCheck listener = new(null, livelinessCheck, (_msg, arg) -> onMessage.get((A) arg));
  listener.verbose = verbose;
  
  Map<S, Set> map = vm_busListenersByMessage_live();
  synchronized(map) {
    Set listeners = map.get(msg);
    if (listeners == null) map.put(msg, listeners = syncIdentityHashSet());
    listener.listeners = listeners;
    // We're technically violating the one-synchronized-object-per-thread rule,
    // but it should be OK here.
    listeners.add(listener);
    ret listener;
  }
}

Author comment

Began life as a copy of #1031570

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031573
Snippet name: vmBus_onMessage_withLivelinessCheck - performs a custom liveliness check before every invocation and drops listener if check fails
Eternal ID of this version: #1031573/8
Text MD5: b4a78691f074e4c641f42c5270d8bc6e
Transpilation MD5: 9587310f9bc71f7abe30a28ac4eb5786
Author: stefan
Category: javax / vm
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-25 01:41:08
Source code size: 725 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 171 / 255
Version history: 7 change(s)
Referenced in: [show references]