// returns last value
sclass PrintPolledValueUntilPredicateOrTimeout {
settable IF0 makeValue;
settable IPred pred; // if true, loop ends
settable double timeout = 60.0;
settable int interval = 100;
settable S printPrefix = "";
*(S *printPrefix, IF0 *makeValue, IPred *pred) {}
void printValue(A a) {
printWithMS(printPrefix, a);
}
A get() {
Timeout timeOut = new(timeout);
A a = makeValue!;
printValue(a);
if (pred != null && pred.get(a))
ret a;
while (!timeOut!) {
A b = makeValue!;
if (!eq(a, b))
printValue(a = b);
if (pred != null && pred.get(a))
break;
else
sleep(interval);
}
ret a;
}
run { get(); }
}