sclass WatchVariable extends Var {
IF0 f;
ReliableSingleThread rst = new(r update_impl);
event change;
*(IF0 *f) {
update();
}
*(IF0 *f, Runnable onChange) {
onChange(onChange);
update();
}
// only run in rst
void update_impl() {
A value = f?!;
if (!eq(value, get())) {
set(value);
change();
}
}
void update aka trigger() {
rst!;
}
}