Hi!
in our team at work we have 2 Hackathons / year and for the next year I would like to introduce Rust As we have in our daily work to do with data processing I am thinking about a challenge to read a huge csv file and to import each lines in parallel into a database like Surrealdb.
As I currently do not have so much experience with Rust generally I do not know what could be a good start for this experimentation.
During my research I came accros the crate Rayon or Tokio.
On www.linkedin.com I found an article from Umur Ozkul which shared this code:
Is this something I can start with?
use tokio::sync::mpsc;
#[tokio::main]
async fn main() {
let (mut producer_tx, mut transformer_rx) = mpsc::channel(32);
let (mut transformer_tx, mut consumer_rx) = mpsc::channel(32);
let producer_handle = tokio::spawn(async move {
for i in 1..=10 {
println!("Producing {}", i);
producer_tx.send(i).await.unwrap();
}
});
let transformer_handle = tokio::spawn(async move {
while let Some(i) = transformer_rx.recv().await {
println!("Transforming {}", i);
transformer_tx.send(i * i).await.unwrap();
}
});
let consumer_handle = tokio::spawn(async move {
while let Some(i) = consumer_rx.recv().await {
println!("Consumed {}", i);
}
});
tokio::try_join!(producer_handle, transformer_handle, consumer_handle).unwrap();
}
Thank you very much,
Pascal