#!/bin/bash

# parallelize and wait for a set of jobs;
# it's MapReduce for `bash`!

FAIL=0

# See http://jeremy.zawodny.com/blog/archives/010717.html

{{for command in commands}}
{{command}} &
{{endfor}}

# wait for processes
for job in `jobs -p`
do
    echo ${job}
    wait ${job} || let "FAIL+=1"
done

if [ "${FAIL}" == "0" ]
then
    exit 0
fi

echo "${FAIL} failing job(s)"
exit 1
