sclass OnStableValue extends WaitForStableValue {
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; }
}