Wait for all jobs and return the exit code of the last failing job. Unlike solutions above, this does not require pid saving. Just bg away, and wait.
function wait_ex {
# this waits for all jobs and returns the exit code of the last failing job
ecode=0
while true; do
wait -n
err="$?"
[ "$err" == "127" ] && break
[ "$err" != "0" ] && ecode="$err"
done
return $ecode
}