Add code for demonstrating concurrency
This commit is contained in:
parent
e52278f0d3
commit
b5625b6c4c
3 changed files with 2137 additions and 1 deletions
async-concurrency
2121
async-concurrency/Cargo.lock
generated
2121
async-concurrency/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
trpl = "0.2.0"
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
trpl::run(async {
|
||||
trpl::spawn_task(async {
|
||||
for i in 1..10 {
|
||||
println!("hi number {i} from the first task!");
|
||||
trpl::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
|
||||
for i in 1..5 {
|
||||
println!("hi number {i} from the second task!");
|
||||
trpl::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue