sclass OnStableValue<A> extends WaitForStableValue<A> { long period; A value; long valueSince; O runnable; A lastStableValue; *() {} *(long *period, O *runnable) {} *(double seconds, O *runnable) { period = toMS(seconds); } synchronized void set(A a) { if (neq(a, value)) { value = a; valueSince = sysNow(); doLater(period, r check); // TODO: slightly dicey } } synchronized void check() { A a = get(); if (neq(a, lastStableValue)) { lastStableValue = a; callF(runnable, a); } } synchronized A get() { ret valueSince != 0 && sysNow() >= valueSince+period ? value : null; } public bool has() { ret get() != null; } }
Began life as a copy of #1015867
download show line numbers debug dex old transpilations
Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1019579 |
Snippet name: | OnStableValue |
Eternal ID of this version: | #1019579/4 |
Text MD5: | e5a3c294e308825ed5038fd977280cd2 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-11-12 20:12:09 |
Source code size: | 746 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 259 / 794 |
Version history: | 3 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |