I was looking at the continuous time examples which use the TimerSystem and at()
to invoke an alarm, and I think for javascript at least where there's a builtin setTimeout
something like this is okay:
const makeAlarm = (cTime:Cell<number>) => {
const sSink = new StreamSink<void>();
cTime.listen(n =>
setTimeout(() => sSink.send(null), n)
);
return sSink;
}
Thoughts? I don't love the listen+send but in this specific case it feels fine since it's by definition a delayed call.
I'm using a variation of this in the new bouncing ball demo which uses the frame tick for the send (alternatively performance.now() could be used too) - though I figured it might help to talk about the idea of an alarm like this separately since it's a general idea
EDIT: btw just to add, in practice the stream sink would include a cancel function and timestamp (this is what's happening in the ball bounce demo), but I kept it out of the sample above for the sake of brevity