Skip to content

Commit 7e3a346

Browse files
authored
Update zsh-async to v1.8.6 (#652)
1 parent 47c0c88 commit 7e3a346

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

async.zsh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#
44
# zsh-async
55
#
6-
# version: v1.8.4
6+
# version: v1.8.6
77
# author: Mathias Fredriksson
88
# url: https://github.com/mafredri/zsh-async
99
#
1010

11-
typeset -g ASYNC_VERSION=1.8.4
11+
typeset -g ASYNC_VERSION=1.8.6
1212
# Produce debug output from zsh-async when set to 1.
1313
typeset -g ASYNC_DEBUG=${ASYNC_DEBUG:-0}
1414

@@ -20,7 +20,7 @@ _async_eval() {
2020
# simplicity, this could be improved in the future.
2121
{
2222
eval "$@"
23-
} &> >(ASYNC_JOB_NAME=[async/eval] _async_job 'cat')
23+
} &> >(ASYNC_JOB_NAME=[async/eval] _async_job 'command -p cat')
2424
}
2525

2626
# Wrapper for jobs executed by the async worker, gives output in parseable format with execution time
@@ -46,7 +46,7 @@ _async_job() {
4646
duration=$(( EPOCHREALTIME - duration )) # Calculate duration.
4747
4848
print -r -n - $'\0'${(q)jobname} $ret ${(q)stdout} $duration
49-
} 2> >(stderr=$(cat) && print -r -n - " "${(q)stderr}$'\0')
49+
} 2> >(stderr=$(command -p cat) && print -r -n - " "${(q)stderr}$'\0')
5050
)"
5151
if [[ $out != $'\0'*$'\0' ]]; then
5252
# Corrupted output (aborted job?), skipping.
@@ -232,7 +232,7 @@ _async_worker() {
232232
# recreate it when there are no other jobs running.
233233
if (( ! coproc_pid )); then
234234
# Use coproc as a mutex for synchronized output between children.
235-
coproc cat
235+
coproc command -p cat
236236
coproc_pid="$!"
237237
# Insert token into coproc
238238
print -n -p "t"
@@ -325,7 +325,7 @@ async_process_results() {
325325
else
326326
# In case of corrupt data, invoke callback with *async* as job
327327
# name, non-zero exit status and an error message on stderr.
328-
$callback "[async]" 1 "" 0 "$0:$LINENO: error: bad format, got ${#items} items (${(q)items})" $has_next
328+
$callback "[async]" 1 "" 0 "$0:$LINENO: error: bad format, got ${#items} items (${(q)items})" $has_next
329329
fi
330330
done
331331
done
@@ -392,6 +392,9 @@ _async_send_job() {
392392
#
393393
# Start a new asynchronous job on specified worker, assumes the worker is running.
394394
#
395+
# Note if you are using a function for the job, it must have been defined before the worker was
396+
# started or you will get a `command not found` error.
397+
#
395398
# usage:
396399
# async_job <worker_name> <my_function> [<function_params>]
397400
#
@@ -561,7 +564,11 @@ async_start_worker() {
561564
# worker.
562565
# See https://github.com/mafredri/zsh-async/issues/35.
563566
integer errfd=-1
564-
exec {errfd}>&2
567+
568+
# Redirect of errfd is broken on zsh 5.0.2.
569+
if is-at-least 5.0.8; then
570+
exec {errfd}>&2
571+
fi
565572

566573
# Make sure async worker is started without xtrace
567574
# (the trace output interferes with the worker).
@@ -570,12 +577,16 @@ async_start_worker() {
570577
unsetopt xtrace
571578
}
572579

573-
zpty -b $worker _async_worker -p $$ $args 2>&$errfd
580+
if (( errfd != -1 )); then
581+
zpty -b $worker _async_worker -p $$ $args 2>&$errfd
582+
else
583+
zpty -b $worker _async_worker -p $$ $args
584+
fi
574585
local ret=$?
575586

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

580591
if (( ret )); then
581592
async_stop_worker $worker

0 commit comments

Comments
 (0)