Created
January 21, 2020 21:22
-
-
Save felipesere/d31c46225f96ac9defd3ca384efe18d0 to your computer and use it in GitHub Desktop.
Race conditions? Block?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn add_items_to_track( | |
db: Arc<dyn Db>, | |
client: Arc<dyn ClientForRepositories + Send + Sync>, | |
id: i32, | |
items: Vec<api::ItemToTrack>, | |
) -> Result<()> { | |
log::info!("We were about to add {:?} to {}", items, id); | |
if let Some(repo) = db.find_repo(id) { | |
let mut tasks = FuturesUnordered::new(); | |
for item in items { | |
let name = repo.name(); | |
let c = client.clone(); | |
let nr = item.nr; | |
tasks.push(task::spawn(async move { | |
match item.kind { | |
ItemKind::Issue => c.issue(&name, nr).await, | |
ItemKind::PR => c.pull_request(&name, nr).await, | |
} | |
})); | |
log::info!("added a new task for {}", nr); | |
}; | |
let number_of_tasks = tasks.len(); | |
log::info!("setup all the tasks: {}", number_of_tasks); | |
let res = task::block_on(async move { | |
let mut res = Vec::new(); | |
while let Some(i) = tasks.next().await { | |
let i = dbg!(i); | |
res.push(i) | |
}; | |
res | |
}); | |
log::info!("done gathering results: {}", number_of_tasks); | |
dbg!(res.len()); | |
bail!("Could not find repo {}", id) | |
} else { | |
bail!("Could not find repo {}", id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment