Replaced Builder::build_results with into_build_results.

It's technically slower because it's got to lock everything, but at this point there should be no other locks (which our old solution relied on), so locking should be pretty fast.
This commit is contained in:
Filipe Rodrigues 2024-08-28 07:48:27 +01:00
parent 5390fb8019
commit fcf3c77971
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
3 changed files with 9 additions and 11 deletions

View File

@ -95,11 +95,13 @@ impl Builder {
}
/// Returns all build results
pub fn into_build_results(self) -> IndexMap<ArcStr, Option<Result<BuildResult, ()>>> {
pub async fn build_results(&self) -> IndexMap<ArcStr, Option<Result<BuildResult, ()>>> {
self.rules_lock
.into_iter()
.map(|(rule, lock)| (rule.name, lock.into_res()))
.iter()
.map(async move |rule_lock| (rule_lock.key().name.clone(), rule_lock.value().res().await))
.collect::<FuturesUnordered<_>>()
.collect()
.await
}
/// Sends an event, if any are subscribers

View File

@ -52,13 +52,9 @@ impl BuildLock {
}
}
/// Retrieves this lock's result by consuming the lock
pub fn into_res(self) -> Option<Result<BuildResult, ()>> {
// TODO: Not panic here
Arc::try_unwrap(self.state)
.expect("Leftover references when unwrapping build lock")
.into_inner()
.res
/// Retrieves this lock's result
pub async fn res(&self) -> Option<Result<BuildResult, ()>> {
self.state.read().await.res
}
}

View File

@ -187,7 +187,7 @@ async fn main() -> ExitResult {
);
// Finally print some statistics
let targets = builder.into_build_results();
let targets = builder.build_results().await;
let total_targets = targets.len();
let built_targets = targets
.iter()