The timers vocabulary provides a lightweight way to schedule one-time and recurring tasks. Timers run in a single green thread per timer and consist of a quotation, a delay duration, and an interval duration. After starting a timer, the timer thread sleeps for the delay duration and calls the quotation. Then it waits out the interval duration and calls the quotation again until something stops the timer. If a recurring timer's quotation would be scheduled to run again before the previous quotation has finished processing, the timer will be run again immediately afterwards. This may result in the timer falling behind indefinitely, in which case the it will run as often as possible while still allowing other green threads to run. Recurring timers that execute 'on time' or 'catch up' will always be scheduled for an exact multiple of the interval from the original starting time to prevent the timer from drifting over time. Timers use nano-count as the timing primitive, so they will continue to work across system clock changes.

The timer class:

Create a timer before starting it:
<timer> ( quot delay-duration/f interval-duration/f -- timer )

Starting a timer:
start-timer ( timer -- )

restart-timer ( timer -- )

Stopping a timer:
stop-timer ( timer -- )

A recurring timer without an initial delay:
every ( quot interval-duration -- timer )

A one-time timer with an initial delay:
later ( quot delay-duration -- timer )

A recurring timer with an initial delay:
delayed-every ( quot duration -- timer )