summaryrefslogtreecommitdiff
path: root/lib/async_prompt.zsh
diff options
context:
space:
mode:
authorLoïc Yhuel <loic.yhuel@gmail.com>2024-04-03 19:42:47 +0200
committerGitHub <noreply@github.com>2024-04-03 19:42:47 +0200
commitb43b84abc77850a3734c127c38afdd7cf7739dc6 (patch)
tree825ace69c087d0c38ec9ed775aca7b3a2820cb92 /lib/async_prompt.zsh
parent130002a79e8567befa409177990bb2724b8edefc (diff)
downloadzsh-b43b84abc77850a3734c127c38afdd7cf7739dc6.tar.gz
zsh-b43b84abc77850a3734c127c38afdd7cf7739dc6.tar.bz2
zsh-b43b84abc77850a3734c127c38afdd7cf7739dc6.zip
fix(async): avoid blocking the shell while waiting (#12304)
Co-authored-by: Marc Cornellà <marc@mcornella.com>
Diffstat (limited to 'lib/async_prompt.zsh')
-rw-r--r--lib/async_prompt.zsh14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/async_prompt.zsh b/lib/async_prompt.zsh
index 384e49d33..ac95bcd73 100644
--- a/lib/async_prompt.zsh
+++ b/lib/async_prompt.zsh
@@ -82,10 +82,8 @@ function _omz_async_request {
exec {fd}< <(
# Tell parent process our PID
builtin echo ${sysparams[pid]}
- # Store handler name for callback
- builtin echo $handler
# Set exit code for the handler if used
- (exit $ret)
+ () { return $ret }
# Run the async function handler
$handler
)
@@ -98,8 +96,7 @@ function _omz_async_request {
command true
# Save the PID from the handler child process
- read pid <&$fd
- _OMZ_ASYNC_PIDS[$handler]=$pid
+ read -u $fd "_OMZ_ASYNC_PIDS[$handler]"
# When the fd is readable, call the response handler
zle -F "$fd" _omz_async_callback
@@ -114,15 +111,14 @@ function _omz_async_callback() {
local err=$2 # Second arg will be passed in case of error
if [[ -z "$err" || "$err" == "hup" ]]; then
- # Get handler name from first line
- local handler
- read handler <&$fd
+ # Get handler name from fd
+ local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}"
# Store old output which is supposed to be already printed
local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}"
# Read output from fd
- _OMZ_ASYNC_OUTPUT[$handler]="$(cat <&$fd)"
+ IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]"
# Repaint prompt if output has changed
if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then