Skip to content
Taskvisor 0.9source v0.9.0

Install Taskvisor ​

Taskvisor requires Rust 1.90 or newer. Add the taskvisor crate to your dependencies:

toml
taskvisor = "0.9"

The default install includes the controller API. To use it, build the supervisor with with_controller.

FeatureDefaultAdds
controllerYesSlot-based admission control.
tracingNoTracingBridge for structured events.
loggingNoLogWriter for readable lifecycle output.
tokio-util-interopNoAccess to the raw cancellation token in TaskContext.
test-utilNoConstructors intended for external integration tests.

Enable an optional integration:

toml
taskvisor = { version = "0.9", features = ["tracing"] }

Build without keyed admission:

toml
taskvisor = { version = "0.9", default-features = false }

Test helpers ​

With test-util enabled, TaskContext::detached and TaskContext::detached_cancelled create contexts for direct task-code tests. TaskId::for_tests creates a fresh process-local ID. TaskOutcome::failed_for_tests, TaskOutcome::fatal_for_tests, and TaskOutcome::rejected_for_tests create failure and rejection values for assertions.

Add the test-only feature and the Tokio test runtime:

toml
[dev-dependencies]
taskvisor = { version = "0.9", features = ["test-util"] }
tokio = { version = "1", features = ["macros", "rt"] }

Test cancellation-aware application code without starting a supervisor:

rust
use taskvisor::{TaskContext, TaskError};

async fn waits_for_work(ctx: &TaskContext) -> Result<(), TaskError> {
    ctx.run_until_cancelled(std::future::pending::<()>()).await?;
    Ok(())
}

#[tokio::test]
async fn observes_cancellation() {
    let ctx = TaskContext::detached_cancelled();

    assert!(matches!(
        waits_for_work(&ctx).await,
        Err(TaskError::Canceled)
    ));
}

For integration tests, start a supervisor with serve, add watched work, assert its TaskOutcome, then join shutdown. See TaskContext and TaskOutcome for the test helpers.

Source: Cargo features and test contexts.

Open-source task execution components.