Skip to content

Commit 6f05757

Browse files
committed
add example to README
1 parent 50318e6 commit 6f05757

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,24 @@ This is a library, with an API inspired by [timer.rs](https://github.com/Yoric/t
44
[![Documentation](https://docs.rs/synchronous-timer/badge.svg)](https://docs.rs/synchronous-timer)
55
[![crates.io](https://img.shields.io/crates/v/synchronous-timer.svg)](https://crates.io/crates/synchronous-timer)
66

7+
Example:
8+
9+
```rust
10+
use std::time::Duration;
11+
use synchronous_timer::Timer;
12+
13+
fn main() {
14+
let mut timer = Timer::new();
15+
timer
16+
.schedule_in(Duration::from_secs(5), || {
17+
println!("I will run on the background thread in 5 seconds")
18+
})
19+
.detach();
20+
timer.schedule_immediately(|| println!("I will run on the background thread right now"));
21+
let handle = timer.schedule_in(Duration::from_secs(1), || println!("I will never run"));
22+
drop(handle);
23+
std::thread::sleep(Duration::from_secs(6));
24+
}
25+
```
26+
727
This work is licensed under the ISC license, a copy of which can be found in [LICENSE.txt](LICENSE.txt).

0 commit comments

Comments
 (0)