Skip to content

Commit

Permalink
Update example supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
iwannay committed Dec 9, 2024
1 parent 8cf655f commit 333b456
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions examples/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ use watchexec_supervisor::{
};

async fn supervisor_test() {
let code = r#"date;
echo hello world
sleep 5 &
echo end"#;

let (job, task) = start_job(Arc::new(Command {
program: Program::Exec {
prog: "/usr/bin/bash".into(),
args: vec!["-c".into(), r#"date;echo hello;sleep 10 &"#.into()],
args: vec!["-c".into(), code.into()],
}
.into(),
options: SpawnOptions {
grouped: false,
grouped: true,
reset_sigmask: true,
},
}));
Expand All @@ -31,16 +36,22 @@ async fn supervisor_test() {
loop {
select! {
_v = clone_job.to_wait() => {
if clone_job.is_dead() {
return;
}
sleep(Duration::from_secs(1)).await;
clone_job.start().await;
}
}
}
});

job.to_wait().await;
sleep(Duration::from_secs(10)).await;
job.stop();
job.delete_now();

let _ = task.await.expect("failed to wait join finished");
sleep(Duration::from_secs(5)).await;
}

#[tokio::main]
Expand Down

0 comments on commit 333b456

Please sign in to comment.