inner_function/
inner_function.rs1use std::{thread, time::Duration};
2
3fn main() {
4 let on_timeout = || {
5 println!("timeout!");
6 };
7
8 let static_on_timeout = Box::leak(Box::new(on_timeout));
11
12 let cancel = spawn_timeout::spawn_timeout(static_on_timeout, Duration::from_secs(3));
13 let _ = spawn_timeout::spawn_timeout(static_on_timeout, Duration::from_secs(3));
14
15 thread::sleep(Duration::from_millis(1500));
17
18 cancel();
19
20 println!("The first instance of spawn_timeout has been succesfully stopped");
21
22 thread::sleep(Duration::from_millis(u64::MAX));
24}