Function Reactor.registerIdleCallback

Register an idle handler callback.

void registerIdleCallback (
  bool delegate(core.time.Duration) dg
) nothrow @safe;

The reactor handles scheduling and fibers switching, but has no built-in mechanism for scheduling sleeping fibers back to execution (except fibers sleeping on a timer, of course). Mechanisms such as file descriptor watching are external, and are registered using this function.

The idler callback should receive a timeout variable. This indicates the time until the closest timer expires. If no other event comes in, the idler should strive to wake up after that long. Waking up sooner will, likely, cause the idler to be called again. Waking up later will delay timer tasks (which is allowed by the API contract).

It is allowed to register more than one idler callback. Doing so, however, will cause all of them to be called with a timeout of zero (i.e. - don't sleep), resulting in a busy wait for events.

The idler is expected to return a boolean value indicating whether the time spent inside the idler is to be counted as idle time, or whether that's considered "work". This affects the results returned by the idleCycles field returned by the reactorStats.