summaryrefslogtreecommitdiffstats
path: root/src/job/runnable.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-01-08 12:07:59 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-01-15 23:08:12 +0100
commitd7d86b67efe088e4412efd975c316a149b52a50a (patch)
tree85e528bd6fa9402f164cdfc11768e8198ac644b9 /src/job/runnable.rs
parent4d14d7028410356897c764ba41bb686e46d3170d (diff)
Refactor: Chain iterators and collect at once
This improves the collection building be reducing the asyncness. The stream is build first and then all futures are collected. Before this patch, two streams were collected and then appended. Not sure whether this improves runtime, but it certainly improves readability. Unfortunately, collecting the additional job resources right into the streams is not that easy and thus the resulting collection is simply extend()ed. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/job/runnable.rs')
-rw-r--r--src/job/runnable.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/job/runnable.rs b/src/job/runnable.rs
index 215fcbc..4a9180f 100644
--- a/src/job/runnable.rs
+++ b/src/job/runnable.rs
@@ -58,27 +58,31 @@ impl RunnableJob {
pub async fn build_from_job(job: Job, merged_stores: &MergedStores, source_cache: &SourceCache, config: &Configuration) -> Result<Self> {
trace!("Preparing build dependencies");
let resources = {
- let deps = job.package().dependencies();
- let build = deps
+ let mut resources = job
+ .package()
+ .dependencies()
.build()
.into_iter()
.map(|dep| Self::build_resource(dep, merged_stores))
+ .chain({
+ job.package()
+ .dependencies()
+ .runtime()
+ .into_iter()
+ .map(|dep| Self::build_resource(dep, merged_stores))
+ })
.collect::<futures::stream::FuturesUnordered<_>>()
- .collect::<Result<Vec<JobResource>>>();
-
- let rt = deps
- .runtime()
- .into_iter()
- .map(|dep| Self::build_resource(dep, merged_stores))
- .collect::<futures::stream::FuturesUnordered<_>>()
- .collect::<Result<Vec<JobResource>>>();
+ .collect::<Result<Vec<JobResource>>>()
+ .await?;
- let (build, rt) = tokio::join!(build, rt);
- let (mut build, mut rt) = (build?, rt?);
+ resources.extend({
+ job.resources()
+ .iter()
+ .filter(|jr| jr.env().is_some())
+ .cloned()
+ });
- build.append(&mut rt);
- build.extend(job.resources().iter().filter(|jr| jr.env().is_some()).cloned());
- build
+ resources
};
if config.containers().check_env_names() {