Libraryless. Click here for Pure Java version (1848L/12K).
sclass Trigger implements Runnable { bool triggered; L<Runnable> onTrigger; *() {} *(Runnable onTrigger) { this.onTrigger = ll(onTrigger); } // for "user" synchronized void trigger() { synchronized(this) { if (triggered) ret; triggered = true; } pcallFAll(onTrigger); } public void run() { trigger(); } // for "implementer" - check if triggered and clear flag synchronized bool check() { if (!triggered) false; ret true with triggered = false; } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022762 |
Snippet name: | Trigger - synchronized boolean flag with trigger(), check() and listeners on triggering |
Eternal ID of this version: | #1022762/12 |
Text MD5: | 9b247338cc8b3631f1d3f9e0ffe3bb71 |
Transpilation MD5: | 42fcd10b1caf0fd789db351892021946 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-06 16:22:57 |
Source code size: | 536 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 334 / 827 |
Version history: | 11 change(s) |
Referenced in: | [show references] |