Libraryless. Click here for Pure Java version (1848L/12K).
1 | sclass Trigger implements Runnable { |
2 | bool triggered; |
3 | L<Runnable> onTrigger; |
4 | |
5 | *() {} |
6 | *(Runnable onTrigger) { this.onTrigger = ll(onTrigger); } |
7 | |
8 | // for "user" |
9 | synchronized void trigger() { |
10 | synchronized(this) { |
11 | if (triggered) ret; |
12 | triggered = true; |
13 | } |
14 | pcallFAll(onTrigger); |
15 | } |
16 | |
17 | public void run() { trigger(); } |
18 | |
19 | // for "implementer" - check if triggered and clear flag |
20 | synchronized bool check() { |
21 | if (!triggered) false; |
22 | ret true with triggered = false; |
23 | } |
24 | } |
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: | 335 / 828 |
Version history: | 11 change(s) |
Referenced in: | [show references] |