akd icon indicating copy to clipboard operation
akd copied to clipboard

Call multiple lookup operations async

Open eozturk1 opened this issue 3 years ago • 2 comments

To improve the efficiency of bulk/multi lookups, we could call lookups async and await on the results of all lookups -- rather than awaiting on them individually.

eozturk1 avatar Mar 09 '22 01:03 eozturk1

Pulled from comment in PR #163

use futures::future;

// generate your vector of individual tasks by spawning them on green threads
// but you need to clone "self" in order to apply on different threads, which will
// shard the data-access pointer and cache pointers, etc to yield individual Directory<_>
// instances on each thread
let tasks = proofs_to_generate.into_iter().map(|proof| {
  let self_clone = self.clone();
  tokio::spawn(async move { self_clone.lookup(proof).await })
}

let outputs = future::try_join_all(tasks).await?;

slawlor avatar Mar 09 '22 21:03 slawlor