Tickers are for when you want to do something repeatedly at regular intervals. Here’s an example of a ticker that ticks periodically until we stop it.
In this Idris program, we simulate a ticker using a separate thread and IORef for communication. The ticker runs every 500 milliseconds, printing the current time at each tick.
We use fork to start a new thread for the ticker. The ticker runs in a loop, checking the done IORef at each iteration to see if it should stop.
The main thread sleeps for 1600 milliseconds, then sets the done IORef to True to stop the ticker. We use an IORef to count the number of ticks that occurred.
When we run this program, the ticker should tick about 3 times before we stop it.
Note that the exact output may vary depending on system performance and timing. The important part is that we see about 3 ticks before the ticker is stopped.