This commit is contained in:
Dmitry Belyaev 2022-09-20 11:39:53 +03:00
parent a0a3ea0fbb
commit 7eaa394d7d
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -263,6 +263,8 @@ async fn data_reader(queue: WriteQueue) {
}
// mark queue as done for writer to exit loop
queue.lock().await.push_back(None);
println!("convert done ✅");
}
async fn data_writer(queue: WriteQueue) {
@ -303,6 +305,8 @@ async fn data_writer(queue: WriteQueue) {
}
}
writer.close().await.unwrap();
println!("write done ✅");
}
#[tokio::main]
@ -313,17 +317,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
_ => (),
};
let queue: WriteQueue = Arc::new(Mutex::new(VecDeque::with_capacity(40)));
let queue: WriteQueue = Arc::new(Mutex::new(VecDeque::with_capacity(5000)));
let queue_r = Arc::clone(&queue);
let queue_w = Arc::clone(&queue);
let res = tokio::try_join!(
tokio::spawn(async move { data_reader(queue_r).await }),
tokio::spawn(async move { data_writer(queue_w).await })
);
tokio::try_join!(
tokio::spawn(data_reader(queue_r)),
tokio::spawn(data_writer(queue_w))
)?;
res?;
println!("done ✅");
println!("all done ✅");
Ok(())
}