-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC the async update default time zone
- Loading branch information
1 parent
d3c0519
commit 4a5a73b
Showing
3 changed files
with
118 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use jiff::tz::TimeZone; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
// The time zone is updated by async thread each 20 seconds. | ||
// And we get the default time zone continuously, | ||
// so we can see the log: `cache is still using, so update the tz.` | ||
for i in 1..=50 { | ||
sleep(Duration::from_secs(1)); | ||
TimeZone::system(); | ||
println!("round 1------{i}"); | ||
} | ||
|
||
// Stop the get the default time zone for a while, so we can see the log : | ||
// `cache is not used so far, so stop this thread.` | ||
for i in 1..=35 { | ||
sleep(Duration::from_secs(1)); | ||
println!("round 2------{i}"); | ||
} | ||
|
||
// Get the default time zone again, we can see | ||
// `try_update_time_zone` log to start the thread again. | ||
// And see the `cache is still using, so update the tz.` log later. | ||
for i in 1..=50 { | ||
sleep(Duration::from_secs(1)); | ||
TimeZone::system(); | ||
println!("round 3------{i}"); | ||
} | ||
|
||
// See the `cache is not used so far, so stop this thread.` log later. | ||
for i in 1..=50 { | ||
sleep(Duration::from_secs(1)); | ||
println!("round 4------{i}"); | ||
} | ||
} |
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