#[fastn_context::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Testing minimal fastn-context API...");
let global_ctx = fastn_context::global();
println!("Global context created: {}", global_ctx.name);
global_ctx
.child("test-service")
.spawn(|service_ctx| async move {
println!("Service context created: {}", service_ctx.name);
tokio::select! {
_ = service_ctx.cancelled() => {
println!("Service context cancelled");
}
_ = tokio::time::sleep(tokio::time::Duration::from_millis(100)) => {
println!("Service context completed");
}
}
});
println!("Global context is cancelled: {}", global_ctx.is_cancelled());
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
println!("\n=== Context Tree Status ===");
let status = fastn_context::status();
println!("{}", status);
global_ctx.spawn_child("persist-test", |task_ctx| async move {
tokio::time::sleep(tokio::time::Duration::from_millis(30)).await;
task_ctx.persist();
});
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
println!("\n=== Status with Persisted Contexts ===");
let status_with_latest = fastn_context::status_with_latest();
println!("{}", status_with_latest);
global_ctx.spawn_child("persist-test", |task_ctx| async move {
tokio::time::sleep(tokio::time::Duration::from_millis(30)).await;
task_ctx.persist();
});
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
println!("\n=== Status with Persisted Contexts ===");
let status_with_latest = fastn_context::status_with_latest();
println!("{}", status_with_latest);
println!("Basic API test completed!");
Ok(())
}