1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-25 21:40:08 +00:00

trap PIPE

This commit is contained in:
romkatv 2020-01-25 11:12:30 +01:00
parent 565492b10e
commit 2dc56d0afe

View file

@ -1,9 +1,7 @@
# invoked in worker: _p9k_worker_main <pgid> # invoked in worker: _p9k_worker_main <pgid>
function _p9k_worker_main() { function _p9k_worker_main() {
local pgid=$1
mkfifo $_p9k__worker_file_prefix.fifo || return mkfifo $_p9k__worker_file_prefix.fifo || return
echo -nE - s${1}$'\x1e' || return echo -nE - s$_p9k_worker_pgid$'\x1e' || return
exec 0<$_p9k__worker_file_prefix.fifo || return exec 0<$_p9k__worker_file_prefix.fifo || return
rm $_p9k__worker_file_prefix.fifo || return rm $_p9k__worker_file_prefix.fifo || return
@ -16,9 +14,9 @@ function _p9k_worker_main() {
local -A _p9k_worker_fds # fd => id$'\x1f'callback local -A _p9k_worker_fds # fd => id$'\x1f'callback
local -A _p9k_worker_inflight # id => inflight count local -A _p9k_worker_inflight # id => inflight count
function _p9k_worker_reply_begin() { print -nr -- e } function _p9k_worker_reply() {
function _p9k_worker_reply_end() { print -nr -- $'\x1e' } print -nr -- e${(pj:\n:)@}$'\x1e' || kill -- -$_p9k_worker_pgid
function _p9k_worker_reply() { print -nr -- e${(pj:\n:)@}$'\x1e' } }
# usage: _p9k_worker_async <work> <callback> # usage: _p9k_worker_async <work> <callback>
function _p9k_worker_async() { function _p9k_worker_async() {
@ -29,6 +27,8 @@ function _p9k_worker_main() {
_p9k_worker_fds[$fd]=$_p9k_worker_request_id$'\x1f'$2 _p9k_worker_fds[$fd]=$_p9k_worker_request_id$'\x1f'$2
} }
trap '' PIPE
{ {
while zselect -a ready 0 ${(k)_p9k_worker_fds}; do while zselect -a ready 0 ${(k)_p9k_worker_fds}; do
[[ $ready[1] == -r ]] || return [[ $ready[1] == -r ]] || return
@ -70,7 +70,7 @@ function _p9k_worker_main() {
done done
done done
} always { } always {
kill -- -$pgid kill -- -$_p9k_worker_pgid
} }
} }
@ -200,12 +200,12 @@ function _p9k_worker_start() {
setopt xtrace setopt xtrace
zmodload zsh/zselect || return zmodload zsh/zselect || return
! { zselect -t0 || (( $? != 1 )) } || return ! { zselect -t0 || (( $? != 1 )) } || return
local pgid=$sysparams[pid] local _p9k_worker_pgid=$sysparams[pid]
_p9k_worker_main $pgid & _p9k_worker_main &
{ {
trap '' PIPE trap '' PIPE
while syswrite $'\x05'; do zselect -t 1000; done while syswrite $'\x05'; do zselect -t 1000; done
kill -- -$pgid kill -- -$_p9k_worker_pgid
} & } &
exec =true) || return exec =true) || return
zle -F $_p9k__worker_resp_fd _p9k_worker_receive zle -F $_p9k__worker_resp_fd _p9k_worker_receive