Background Jobs and wait
BashFan out work to background processes and wait for them all.
#!/usr/bin/env bash
set -euo pipefail
work() {
sleep "$1"
printf 'task %s done\n' "$1"
}
for n in 3 1 2; do
work "$n" &
done
wait
printf 'all done\n'