Skip to content

Commit

Permalink
Ensure coproc spawned by async_worker_eval is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri committed Sep 29, 2018
1 parent 14f9ac8 commit 847a9d8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ _async_worker() {
unset $zsh_hook_functions # And hooks with registered functions.
unset zsh_hooks zsh_hook_functions # Cleanup.

child_exit() {
close_idle_coproc() {
local -a pids
pids=(${${(v)jobstates##*:*:}%\=*})

Expand All @@ -102,6 +102,10 @@ _async_worker() {
coproc :
coproc_pid=0
fi
}

child_exit() {
close_idle_coproc

# On older version of zsh (pre 5.2) we notify the parent through a
# SIGWINCH signal because `zpty` did not return a file descriptor (fd)
Expand Down Expand Up @@ -197,7 +201,6 @@ _async_worker() {
if (( do_eval )); then
shift cmd # Strip _async_eval from cmd.
_async_eval $cmd
do_eval=0
else
# Run job in background, completed jobs are printed to stdout.
_async_job $cmd &
Expand All @@ -206,6 +209,14 @@ _async_worker() {
fi

processing=0 # Disable guard.

if (( do_eval )); then
do_eval=0

# When there are no active jobs we can't rely on the CHLD trap to
# manage the coproc lifetime.
close_idle_coproc
fi
done
}

Expand Down

0 comments on commit 847a9d8

Please sign in to comment.