Libraryless. Click here for Pure Java version (8037L/45K).
1 | // returns last value |
2 | sclass PrintPolledValueUntilPredicateOrTimeout<A> { |
3 | settable IF0<A> makeValue; |
4 | settable IPred<A> pred; // if true, loop ends |
5 | settable double timeout = 60.0; |
6 | settable int interval = 100; |
7 | settable S printPrefix = ""; |
8 | |
9 | *(S *printPrefix, IF0<A> *makeValue, IPred<A> *pred) {} |
10 | |
11 | void printValue(A a) { |
12 | printWithMS(printPrefix, a); |
13 | } |
14 | |
15 | A get() { |
16 | Timeout timeOut = new(timeout); |
17 | A a = makeValue!; |
18 | printValue(a); |
19 | if (pred != null && pred.get(a)) |
20 | ret a; |
21 | while (!timeOut!) { |
22 | A b = makeValue!; |
23 | if (!eq(a, b)) |
24 | printValue(a = b); |
25 | if (pred != null && pred.get(a)) |
26 | break; |
27 | else |
28 | sleep(interval); |
29 | } |
30 | ret a; |
31 | } |
32 | |
33 | run { get(); } |
34 | } |
Began life as a copy of #1024356
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035352 |
Snippet name: | PrintPolledValueUntilPredicateOrTimeout |
Eternal ID of this version: | #1035352/13 |
Text MD5: | ba6fa224b08a6ae126a14b87e745c22d |
Transpilation MD5: | 2e81a65c0e893a76cc869be3730f9cf9 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-01 20:14:20 |
Source code size: | 776 bytes / 34 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 185 / 332 |
Version history: | 12 change(s) |
Referenced in: | [show references] |