Add code for demonstrating concurrency

This commit is contained in:
Manuel Thalmann 2025-04-05 12:28:41 +02:00
parent e52278f0d3
commit b5625b6c4c
Signed by: manuth
SSH key fingerprint: SHA256:HsMLC+7kJWALP6YCYCoopxNbUnghwSGLVcG76SECT5c
3 changed files with 2137 additions and 1 deletions
async-concurrency

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
trpl = "0.2.0"

View file

@ -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;
}
});
}