Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 512973a..a718a18 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -347,8 +347,29 @@ fakebuild() {
        rm -rf "$work_dir"
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+       while [[ $# -gt 0 ]]; do
+               job_count=($(jobs -p))
+               if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+                       fakebuild "$1" &
+                       shift
+               fi
+               sleep 0.1
+       done
+       wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+       parallelize "$@"
+else
+       for PKG in $@; do fakebuild $PKG; done
+fi
 msg "Done."
 
 exit 0
-- 
2.9.3

Reply via email to