async_channel.rs

Rust•マスター

Explorer

C40
C++40
C#40
Dart40
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust
初級10
中級10
上級10
エキスパート5
マスター5
async_channel.rs
lifetime_bounds.rs
trait_object.rs
macro_recursive.rs
unsafe_transmute.rs
Shell40
Swift40
TypeScript40
async_channel.rs
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
13
use tokio::sync::mpsc;↵
async fn worker(mut rx: mpsc::Receiver<Task>) {↵
   while let Some(task) = rx.recv().await {↵
       match process(task).await {↵
           Ok(result) => tx.send(result).await.unwrap(),↵
           Err(e) => eprintln!("Error: {:?}", e),↵
       }↵
   }↵
}↵
let (tx, rx) = mpsc::channel::<Task>(100);↵
for _ in 0..4 {↵
   tokio::spawn(worker(rx.clone()));↵
}
0WPM•0%•0:00•0/370(0%)|Ln 1, Col 1
UTF-8•Rust

関連する練習問題