3.6 Rescheduling Repeating Timers

The cancellation and rescheduling of repeating timers behaves identically to the cancellation and rescheduling of one-shot timers. However, there is one non-obvious way in which timers may be rescheduled. Specifically, it is possible to reschedule a repeating timer as a one-shot timer and vice-versa. In practise this is because a one-shot timer is equivalent to a repeating timer with the interval field set to zero - interpreted as `don't repeat'.


\begin{listing}
% latex2html id marker 719\begin{small}\begin{verbatim}...
...
...small}\caption{Rescheduling a Repeating Timer as a One-Shot Timer}
\end{listing}

The example shown in Listing 3.7 demonstrates the way in which a repeating timer may be rescheduled as a one-shot timer. This is a minor change to the example previously given in Listing 3.6. On the penultimate call to the timeable callback handler the timer is now rescheduled as a one-shot timer with a 5 second delay. The full code for this example is included in the timer examples package as RepeatingTimerExample3.

A final thing of note about the example shown in Listing 3.7 is that the timer is being rescheduled within the timeable callback handler. This is legitimate since the reactor is designed in such a way that there are no problems with rescheduling or cancelling a timer from within its own callback handler.