iet-runtime-tokio
Supervises workers with owned tasks and bounded drain; it does not install signal handlers.
iet-runtime-tokioimplementationTokio runtimeHow to use it
iet-runtime-tokio is the Tokio implementation of the iet-app runtime contract. You describe the processes to supervise as Workers that receive a TaskSpawner, hand them to TokioRuntime, and supply the shutdown future; on stop it cancels workers, drains owned tasks, and reports worker failures.
// examples/htmx-starter/servers/web/src/lifecycle.rs
use ;
use ;
use Duration;
let probes = new?;
let drain = from_secs;
new?
.run
.await
TokioRuntime::new(drain)rejects a zero or >1h drain window; the drain timeout bounds how long remaining workers may finish before they are aborted.- A worker returning early or failing stops the runtime; the returned
AppErrorcarries that worker's error orruntime.shutdown_timeout. health::HealthWorkerperiodically runs theiet-apphealth registrations and is itself just aWorker, supervised the same way.
How it works
TokioRuntime::run gives the Workers a TaskSpawner backed by a JoinSet and a watch stop channel; each spawned future wraps the worker in a telemetry span, injects a Stop handle, and runs it under iet_telemetry::Stage. It then selects between the caller's shutdown future and the first worker finishing, broadcasts stop so each Stop::cancelled resolves, drains remaining tasks within the drain deadline, and aborts and awaits anything still stuck.
sequenceDiagram participant A as "Application" participant R as "TokioRuntime" participant W as "Workers" participant T as "Tasks" A->>R: run with shutdown future R->>W: Workers::start W->>T: TaskSpawner::spawn A-->>R: shutdown completes R->>T: send stop signal T->>W: Stop::cancelled R->>R: drain within drain timeout R-->>A: AppResult
What it implements
What's inside
Modules
src/health.rssrc/lib.rs
Public API
(root)
- struct
Stop - struct
TokioRuntime pub fn new(drain: Duration) -> AppResult<Self>
health
- struct
HealthWorker pub fn new( health: Health, interval: Duration, timeout: Duration, round_timeout: Duration, ) -> iet_core::AppResult<Self>
Impl map
Worker for HealthWorkerShutdown for StopTaskSpawner<Stop> for TasksDrop for TasksRuntime for TokioRuntimeiet_config::ConfigSource for SourceModule for TestModuleDrop for TestWorkerWorker for TestWorkerModule for Failed
Depends on
External crates: tokio
Used by
- No other framework crate depends on it directly.
In this repository
examples/htmx-starter
Source: crates/features/iet-runtime-tokio