Skip to content

Commit 57d9500

Browse files
committed
[chore] update
1 parent c7693c3 commit 57d9500

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

examples/control.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use tokio_util::sync::CancellationToken;
1616

1717
#[tokio::main(flavor = "current_thread")]
1818
async fn main() -> anyhow::Result<()> {
19-
let sup = Arc::new(taskvisor::Supervisor::new(taskvisor::SupervisorConfig::default(), vec![]));
19+
let sup = Arc::new(taskvisor::Supervisor::new(
20+
taskvisor::SupervisorConfig::default(),
21+
vec![],
22+
));
2023
let runner = Arc::clone(&sup);
2124
tokio::spawn(async move {
2225
let _ = runner.run(vec![]).await;
@@ -69,20 +72,26 @@ async fn main() -> anyhow::Result<()> {
6972
}
7073

7174
fn make_worker(name: &'static str) -> taskvisor::TaskSpec {
72-
let task: taskvisor::TaskRef = taskvisor::TaskFn::arc(name, move |ctx: CancellationToken| async move {
73-
println!("{:>4}[{name}] started", "");
75+
let task: taskvisor::TaskRef =
76+
taskvisor::TaskFn::arc(name, move |ctx: CancellationToken| async move {
77+
println!("{:>4}[{name}] started", "");
7478

75-
let mut counter = 0u32;
76-
loop {
77-
if ctx.is_cancelled() {
78-
println!("{:>4}[{name}] cancelled", "");
79-
return Err(taskvisor::TaskError::Canceled);
80-
}
79+
let mut counter = 0u32;
80+
loop {
81+
if ctx.is_cancelled() {
82+
println!("{:>4}[{name}] cancelled", "");
83+
return Err(taskvisor::TaskError::Canceled);
84+
}
8185

82-
counter += 1;
83-
println!("{:>4}[{name}] tick #{counter}", "");
84-
tokio::time::sleep(Duration::from_millis(500)).await;
85-
}
86-
});
87-
taskvisor::TaskSpec::new(task, taskvisor::RestartPolicy::Always, taskvisor::BackoffPolicy::default(), None)
86+
counter += 1;
87+
println!("{:>4}[{name}] tick #{counter}", "");
88+
tokio::time::sleep(Duration::from_millis(500)).await;
89+
}
90+
});
91+
taskvisor::TaskSpec::new(
92+
task,
93+
taskvisor::RestartPolicy::Always,
94+
taskvisor::BackoffPolicy::default(),
95+
None,
96+
)
8897
}

0 commit comments

Comments
 (0)