Skip to content

Commit

Permalink
Fix async_start_worker on zsh 5.0.2 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri committed Sep 29, 2020
1 parent 3148cb5 commit e3550a3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ async_start_worker() {
# worker.
# See https://github.com/mafredri/zsh-async/issues/35.
integer errfd=-1
exec {errfd}>&2

# Redirect of errfd is broken on zsh 5.0.2.
if is-at-least 5.0.8; then
exec {errfd}>&2
fi

# Make sure async worker is started without xtrace
# (the trace output interferes with the worker).
Expand All @@ -570,12 +574,16 @@ async_start_worker() {
unsetopt xtrace
}

zpty -b $worker _async_worker -p $$ $args 2>&$errfd
if (( errfd != -1 )); then
zpty -b $worker _async_worker -p $$ $args 2>&$errfd
else
zpty -b $worker _async_worker -p $$ $args
fi
local ret=$?

# Re-enable it if it was enabled, for debugging.
(( has_xtrace )) && setopt xtrace
exec {errfd}>& -
(( errfd != -1 )) && exec {errfd}>& -

if (( ret )); then
async_stop_worker $worker
Expand Down

0 comments on commit e3550a3

Please sign in to comment.