# Idling

Dusk's "main" execution loop is to repeatedly fetch word from its input source
and execute it. If the input source is interactive, it means that it spends the
vast majority of its time waiting for this source.

The unit at [lib/idle.fs] provides "idle", which allows you to use this time to
do other tasks one after the other.

This unit holds a linked list of routines that are called one after the other
whenever "idle" is called.

You could, for example, want to maintain some debug information at specific
coordinates of your Grid subsystem. Or, if you have a mouse subsystem, you'll
want to regularly update its coordinates. You would do that through "idle".

All units in Dusk needing to do some idling do so through this unit.

## Example usage


  needs lib/idle
  variable mycounter
  :> 1 mycounter +! ; idleadd
  ...
  mycounter @ . \ This number should be going up very fast

## Implementation details

The idle loop is a list of routines in which we keep track of the next routine
to call. Calling "idle" simply calls that routine select the next one in the
list for the next "idle" call. In other words, "idle" calls *one* item in the
loop.

"idle" doesn't have to be called only by "key". In can also be called by a word
that is doing a time-intensive task. That those tasks call "idle" is what
enables multi-tasking.

There's an important caveat with idle: if you call it in a "low" enough place, a
driver for example, you are likely to end up in an infinite self-referential
loop.

Therefore, calling "idle" is for high level loops, not drivers. When drivers
need to wait, they should use [drv/timer].

## API

idle ( -- )
  Call the next word of the idle loop.

idleadd ( xt -- )
  Add word "xt" to the idle loop.
