Skip to content

Commit b200205

Browse files
committed
performance improvement
1 parent ecdc0d0 commit b200205

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/main.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ impl Cron {
2323
async fn start_cron(&self) {
2424
loop {
2525
sleep(Duration::from_millis(self.sleep_time)).await;
26-
self.execute_command().await;
26+
self.execute_command();
2727
}
2828
}
2929

30-
async fn execute_command(&self) {
31-
print!("CRON::{} =>", self.name);
32-
let _ = Command::new("sh")
33-
.arg("-c")
34-
.arg(self.command.clone())
35-
.stdout(Stdio::inherit())
36-
.status()
37-
.await;
38-
println!("end");
39-
30+
fn execute_command(&self) {
31+
println!("{} => ", self.name);
32+
let x = |command: String| {
33+
tokio::spawn(async move {
34+
let _ = Command::new("sh")
35+
.arg("-c")
36+
.arg(command.clone())
37+
.stdout(Stdio::inherit())
38+
.status().await;
39+
});
40+
};
41+
x(self.command.clone());
4042
}
4143
}
4244

0 commit comments

Comments
 (0)