MCPcopy Create free account
hub / github.com/AI45Lab/Code / main

Function main

examples/test_cancel.rs:6–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[tokio::main]
6async fn main() -> anyhow::Result<()> {
7 // Create agent from config
8 let agent = Agent::new("~/.a3s/config.acl").await?;
9 let session = agent.session(".")?;
10
11 println!("Starting long-running operation...");
12
13 // Spawn a task to cancel after 3 seconds
14 let session_clone = session.clone();
15 tokio::spawn(async move {
16 sleep(Duration::from_secs(3)).await;
17 println!("\n🛑 Cancelling operation...");
18 let cancelled = session_clone.cancel().await;
19 println!("Cancelled: {}", cancelled);
20 });
21
22 // Start a long operation
23 let result = session
24 .send("Write a very long story about a robot learning to code. Make it at least 5000 words.", None)
25 .await;
26
27 match result {
28 Ok(r) => {
29 println!("\n✅ Operation completed (possibly partial)");
30 println!("Response length: {} chars", r.text.len());
31 println!("First 200 chars: {}", &r.text.chars().take(200).collect::<String>());
32 }
33 Err(e) => {
34 println!("\n❌ Operation failed: {}", e);
35 }
36 }
37
38 Ok(())
39}

Callers

nothing calls this directly

Calls 4

sessionMethod · 0.45
cloneMethod · 0.45
cancelMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected