Skip to content

Commit

Permalink
Renice the async worker (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
symphorien authored and sindresorhus committed Dec 6, 2019
1 parent 742471d commit 3b182b0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ prompt_pure_async_git_arrows() {
command git rev-list --left-right --count HEAD...@'{u}'
}

# Try to lower the priority of the worker so that disk heavy operations
# like `git status` has less impact on the system responsivity.
prompt_pure_async_renice() {
setopt localoptions noshwordsplit

if command -v renice >/dev/null; then
command renice +15 -p $$
fi

if command -v ionice >/dev/null; then
command ionice -c 3 -p $$
fi
}

prompt_pure_async_tasks() {
setopt localoptions noshwordsplit

Expand All @@ -339,6 +353,7 @@ prompt_pure_async_tasks() {
async_start_worker "prompt_pure" -u -n
async_register_callback "prompt_pure" prompt_pure_async_callback
typeset -g prompt_pure_async_init=1
async_job "prompt_pure" prompt_pure_async_renice
}

# Update the current working directory of the async worker.
Expand Down Expand Up @@ -503,6 +518,8 @@ prompt_pure_async_callback() {
;;
esac
;;
prompt_pure_async_renice)
;;
esac

if (( next_pending )); then
Expand Down

0 comments on commit 3b182b0

Please sign in to comment.