You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the very interesting crawler implementation in ch-05, i'm struggling with the fact that async block at crawler.rs:137 does not need to be move. queued_url is String that is not Copy so, even if it is cloneed inside the closure passed to for_each_concurrent, this should not suffice, it is borrowed inside the async block. I reprodued the problem with a similar (I think) example:
use futures::stream::StreamExt;use tokio::sync::mpsc::{channel,Receiver,Sender};use tokio_stream::wrappers::ReceiverStream;#[tokio::main]asyncfnmain(){let v:Vec<String> = vec!["1".into(), "2".into(), "3".into()];let(tx, rx):(Sender<String>,Receiver<String>) = channel(3);let f = tokio::spawn(asyncmove{ReceiverStream::new(rx).for_each_concurrent(3, |val| {let val = val.clone();async{// <-- This needs to be moveprintln!("Processed value: {}", val.clone());}}).await;});for i in v.iter(){
tx.send(i.clone()).await.unwrap();}drop(tx);
f.await.unwrap();println!("Finished");}
The above code does not compile because of the missing moveasync block highlighted by the comment in the above snippet.
The text was updated successfully, but these errors were encountered:
Looking at the very interesting crawler implementation in ch-05, i'm struggling with the fact that
async
block atcrawler.rs:137
does not need to bemove
.queued_url
isString
that is notCopy
so, even if it isclone
ed inside the closure passed tofor_each_concurrent
, this should not suffice, it is borrowed inside theasync
block. I reprodued the problem with a similar (I think) example:The above code does not compile because of the missing
move
async
block highlighted by the comment in the above snippet.The text was updated successfully, but these errors were encountered: