我一直在努力使这个
store_result
在此方法链中执行:
let (tasks, files): (Vec<_>, Vec<_>) = result_files
.into_iter()
.filter(|x| should_download_file(&provider_id_path, x.filename.clone()))
.map(download_file)
.unzip();
let results = future::join_all(tasks).await;
let store_result = |x: (Result<Response, Error>, Result<File, std::io::Error>)| async {
//info!("Storing result: {:?}, {:?}", x.0, x.1);
// make sure both are Oks
let (result, file) = match (x.0, x.1) {
(Ok(result), Ok(file)) => {
info!("Got result and file.");
info!("Result: {:?}", result.url());
info!("File: {:?}", file);
(result, file)
}
_ => {
error!("Failed to get result and file.");
return;
}
};
// Write bytes to file
let _ = write_bytes_to_file(file, result).await;
};
// Map result and file to store_result
let _ = results
.into_iter()
.zip(files)
.map(|x| async {
debug!("Storing result: {:?}, {:?}", x.0, x.1);
let _ = store_result(x).await;
})
.collect::<Vec<_>>();
info!("Batch download done.");
future::join_all(tasks).await;
已正确执行。代码有什么问题吗?
我以前经历过这个,但不知何故我错过了:
// Map result and file to store_result
let store_results = results
.into_iter()
.zip(files)
.map(|x| async {
debug!("Storing result: {:?}, {:?}", x.0, x.1);
let _ = store_result(x).await;
})
.collect::<Vec<_>>();
let _ = future::join_all(store_results).await;