Libraryless. Click here for Pure Java version (94L/1K).
1 | // assumes that each set function is called exactly once |
2 | // (but it doesn't matter which thread you call each of them from.) |
3 | sclass LongPairCollector > AtomicCounter {
|
4 | volatile long valueOfA; |
5 | volatile long valueOfB; |
6 | |
7 | final LongConsumer a = l1 setA; |
8 | final LongConsumer b = l1 setB; |
9 | |
10 | void setA(long a) { valueOfA = a; itemReceived(); }
|
11 | void setB(long b) { valueOfB = b; itemReceived(); }
|
12 | |
13 | LongConsumer setA aka setterForA() { ret a; }
|
14 | LongConsumer setB aka setterForB() { ret b; }
|
15 | |
16 | void itemReceived {
|
17 | if (incCounter() == 2) |
18 | complete(valueOfA, valueOfB); |
19 | } |
20 | |
21 | // override me |
22 | void complete(long a, long b) {}
|
23 | } |
Began life as a copy of #1035562
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1035570 |
| Snippet name: | LongPairCollector - concurrent collector for 2 longs with overridable complete() function |
| Eternal ID of this version: | #1035570/12 |
| Text MD5: | 062cdc18c08e3cf9746be281b5723891 |
| Transpilation MD5: | 4a0107cfa16ac9f48077005870f06875 |
| Author: | stefan |
| Category: | javax / parallelism |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-06-19 06:16:53 |
| Source code size: | 669 bytes / 23 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 622 / 773 |
| Version history: | 11 change(s) |
| Referenced in: | [show references] |