By using join_all
we can execute a batch of futures simultaneously and get the results at once, but sometime we need to map the original parameter with its result, how can we achieve that? Like the code below, I want to know which result
associates with the tx_id
passed into the future, can we make this?
let fs = items
.iter()
.map(|item| {
let tx_id = item.block_transaction_id.clone();
let c = self
.block_client
.get_transaction_height(tx_id.clone())
.map(|c| (tx_id, c)); // How can I pass tx_id associated to the future to the end?
c
})
.collect_vec();
let results = futures::future::join_all(fs).await;
for result in results {
match result {
Ok((tx_id, h)) => {},
Err(e) => {}
}
}