Skip to content

Commit

Permalink
add example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Roguelazer committed Jun 6, 2022
1 parent 50318e6 commit 6f05757
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@ This is a library, with an API inspired by [timer.rs](https://github.com/Yoric/t
[![Documentation](https://docs.rs/synchronous-timer/badge.svg)](https://docs.rs/synchronous-timer)
[![crates.io](https://img.shields.io/crates/v/synchronous-timer.svg)](https://crates.io/crates/synchronous-timer)

Example:

```rust
use std::time::Duration;
use synchronous_timer::Timer;

fn main() {
let mut timer = Timer::new();
timer
.schedule_in(Duration::from_secs(5), || {
println!("I will run on the background thread in 5 seconds")
})
.detach();
timer.schedule_immediately(|| println!("I will run on the background thread right now"));
let handle = timer.schedule_in(Duration::from_secs(1), || println!("I will never run"));
drop(handle);
std::thread::sleep(Duration::from_secs(6));
}
```

This work is licensed under the ISC license, a copy of which can be found in [LICENSE.txt](LICENSE.txt).

0 comments on commit 6f05757

Please sign in to comment.