Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,9 @@
|
|||
(import random)
|
||||
|
||||
(let printer (fun (val) {
|
||||
(sys:sleep (mod (random) 1000))
|
||||
(print val) }))
|
||||
|
||||
(async printer "Enjoy")
|
||||
(async printer "Rosetta")
|
||||
(async printer "Code")
|
||||
15
Task/Concurrent-computing/Rust/concurrent-computing-2.rs
Normal file
15
Task/Concurrent-computing/Rust/concurrent-computing-2.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use tokio::task::JoinSet;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let words = vec!["Enjoy", "Rosetta", "Code"];
|
||||
let mut set = JoinSet::new();
|
||||
|
||||
for word in words {
|
||||
set.spawn(async move {
|
||||
println!("{}", word);
|
||||
});
|
||||
}
|
||||
|
||||
set.join_all().await;
|
||||
}
|
||||
26
Task/Concurrent-computing/Rust/concurrent-computing-3.rs
Normal file
26
Task/Concurrent-computing/Rust/concurrent-computing-3.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use tokio::{sync::mpsc, task::JoinSet};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let words = vec!["Enjoy", "Rosetta", "Code"];
|
||||
let mut set = JoinSet::new();
|
||||
|
||||
let (tx, mut rx) = mpsc::channel(words.len());
|
||||
|
||||
for word in words {
|
||||
let tx = tx.clone();
|
||||
set.spawn(async move {
|
||||
tx.send(word).await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
drop(tx);
|
||||
|
||||
tokio::spawn(async move {
|
||||
set.join_all().await;
|
||||
});
|
||||
|
||||
while let Some(word) = rx.recv().await {
|
||||
println!("{}", word);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue