Update container's packages in parallel?

I’m using this script to update all my LXD containers:

# Set full path to bins
_apt="/usr/bin/apt"
_pacman="/usr/bin/pacman"
_lxc="/usr/bin/lxc"
_awk="/usr/bin/awk"
_paru="/usr/sbin/paru"

# Get containers list
clist="$(${_lxc} list -c ns | ${_awk} '!/NAME/{ if ( $4 == "RUNNING" ) print $2}')"

function update_container() {

    container=$1
    echo "[Info] Updating $container"

    if ${_lxc} exec $container ${_apt} -- -v &> /dev/null
    then
      echo "with apt"
      ${_lxc} exec $container ${_apt} -- update
      ${_lxc} exec $container ${_apt} -- -y full-upgrade
      ${_lxc} exec $container ${_apt} -- -y clean
      ${_lxc} exec $container ${_apt} -- -y autoclean

    elif ${_lxc} exec $container ${_paru} -- --version &> /dev/null
    then
      echo "with paru"
      ${_lxc} exec --user 1000 $container -- ${_paru} -Syyu
      ${_lxc} exec $container ${_paru} -- -Sc --noconfirm

    else
      echo "with pacman"
      ${_lxc} exec $container ${_pacman} -- -Syyu
      ${_lxc} exec $container ${_pacman} -- -Sc --noconfirm
    fi
}

for c in $clist
do
  update_container $c
done

but of course it updates the containers one at a time, which can be slow. Is it possible to run something like this on all my LXD containers in parallel to update all at once? I know the Paru one will need some work, since it needs sudo input, but I think I can work around that somehow (or just disable it for now).

Ansible can be helpful here, there is an available connection plugin for LXD : Linux Containers - LXD - Third-party integrations

It doesn’t use SSH, it’s much like what you are doing here with your scripts.

Finally, there is also a video from @stgraber available on YT on this topic : LXD and Ansible - YouTube

you can simply rewrite script to use parallel (GNU Parallel - GNU Project - Free Software Foundation)