Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build and Extend It

Run the complete example:

cd examples/toy-job-runner
cargo test
cargo run

Read src/lib.rs in this order:

  1. JobHandle<T, E> and its IntoFuture implementation;
  2. JobRunner::submit and the per-job oneshot pair;
  3. ErasedJob and why its output is ();
  4. dispatch and its JoinSet admission condition;
  5. shutdown and the accepting/stopped state transitions;
  6. the three invariant-focused tests.

Then implement these extensions one at a time:

  1. try_submit returning Full versus ShuttingDown without awaiting.
  2. A Job trait adapter implemented in terms of the future API.
  3. Caller-supplied job weights with a semaphore-based total budget.
  4. Explicit cancellation whose handle drop still remains inert.
  5. Multiple runner instances with different queue/concurrency policies.
  6. Metrics for queued, running, completed, failed, and abandoned results.

Only after that compare the toy with Apalis. The toy’s futures are arbitrary in-memory work; Apalis payloads cross durable backend and codec boundaries. That one requirement explains much of the production library’s additional generic and lifecycle machinery.