forked from jaemk/cached
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add async support and examples for async_std and tokio
- Loading branch information
Showing
6 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use async_std::task::sleep; | ||
use cached::proc_macro::cached; | ||
use std::time::Duration; | ||
|
||
async fn sleep_secs(secs: u64) { | ||
sleep(Duration::from_secs(secs)).await; | ||
} | ||
|
||
#[cached] | ||
async fn cached_sleep_secs(secs: u64) { | ||
sleep(Duration::from_secs(secs)).await; | ||
} | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
println!("sleeping for 4 seconds"); | ||
sleep_secs(4).await; | ||
println!("sleeping for 4 seconds"); | ||
sleep_secs(4).await; | ||
println!("cached sleeping for 4 seconds"); | ||
cached_sleep_secs(4).await; | ||
println!("cached sleeping for 4 seconds"); | ||
cached_sleep_secs(4).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use cached::proc_macro::cached; | ||
use std::time::Duration; | ||
use tokio::time::delay_for; | ||
|
||
async fn sleep_secs(secs: u64) { | ||
delay_for(Duration::from_secs(secs)).await; | ||
} | ||
|
||
#[cached] | ||
async fn cached_sleep_secs(secs: u64) { | ||
delay_for(Duration::from_secs(secs)).await; | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
println!("sleeping for 4 seconds"); | ||
sleep_secs(4).await; | ||
println!("sleeping for 4 seconds"); | ||
sleep_secs(4).await; | ||
println!("cached sleeping for 4 seconds"); | ||
cached_sleep_secs(4).await; | ||
println!("cached sleeping for 4 seconds"); | ||
cached_sleep_secs(4).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters