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 // mark queue as done for writer to exit loop
queue.lock().await.push_back(None); queue.lock().await.push_back(None);
println!("convert done ✅");
} }
async fn data_writer(queue: WriteQueue) { async fn data_writer(queue: WriteQueue) {
@ -303,6 +305,8 @@ async fn data_writer(queue: WriteQueue) {
} }
} }
writer.close().await.unwrap(); writer.close().await.unwrap();
println!("write done ✅");
} }
#[tokio::main] #[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_r = Arc::clone(&queue);
let queue_w = Arc::clone(&queue); let queue_w = Arc::clone(&queue);
let res = tokio::try_join!( tokio::try_join!(
tokio::spawn(async move { data_reader(queue_r).await }), tokio::spawn(data_reader(queue_r)),
tokio::spawn(async move { data_writer(queue_w).await }) tokio::spawn(data_writer(queue_w))
); )?;
res?; println!("all done ✅");
println!("done ✅");
Ok(()) Ok(())
} }