TermBuf::Input::Timers
Wake-ups, delivered down the same channel as the bytes.
A timer is a fibre that sleeps and then puts a Tick on the reader's
inbound channel. Going through that channel rather than a select on a
timeout is what puts wake-ups in order with everything else the terminal
said: a reply that arrived before a timer was armed is dispatched before
that timer's tick, every time, because it was on the channel first.
Cancellation cannot be atomic with a sleep that has already finished, so
it is not tried. A nonce is removed from the live set by #cancel, and
whoever takes the tick off the channel calls #claim to find out whether
the nonce is still worth acting on. A timer cancelled while its tick was
in flight is dropped on receipt.
One fibre per timer. An application arms a handful at a time — a repaint deadline, an idle timeout, the decoder's own escape deadline — and at those volumes a sleeping fibre is cheaper than a heap of them and a thread to service it.
Constructors
Instance methods
Arms a timer for span from now and returns the nonce naming it.
Disarms the timer nonce names.
Safe at any point in that timer's life: before it fires nothing is sent, and after it fires the tick is dropped when it is claimed. What it does not do is stop the fibre, which wakes up to find its nonce gone and ends.
Takes nonce out of the live set, saying whether it was still in it.
Called on the receiving end for every tick: false means the timer was cancelled somewhere between its sleep ending and its tick being read, and the tick means nothing. A timer fires once, so claiming it is also what retires it.