From f7321f6d5b3c6838b9cf05e8f3df3a275f2f528b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 27 Mar 2021 23:04:13 -0400 Subject: [PATCH] Allow close callback to run before leaving job wait loop Apparently, both job_status() == "dead" and ch_status() == "closed" isn't enough to guarantee all callbacks have run. One last sleep seems to do the trick, but let's also add a sanity check because this can cause confusing, hard to debug behavior. --- autoload/fugitive.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 8272612..2e76ece 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2501,9 +2501,10 @@ endfunction function! s:RunTick(job) abort if type(a:job) == v:t_number return jobwait([a:job], 1)[0] == -1 - elseif type(a:job) == v:t_job && (ch_status(a:job) !=# 'closed' || job_status(a:job) ==# 'run') + elseif type(a:job) == 8 + let running = ch_status(a:job) !=# 'closed' || job_status(a:job) ==# 'run' sleep 1m - return ch_status(a:job) !=# 'closed' || job_status(a:job) ==# 'run' + return running endif endfunction @@ -2536,6 +2537,9 @@ function! s:RunWait(state, tmp, job) abort endif endif endwhile + if !has_key(a:state, 'request') && has_key(a:state, 'job') && exists('*job_status') && job_status(a:job) ==# "dead" + throw 'fugitive: close callback did not fire; this should never happen' + endif call s:RunEcho(a:tmp) echo call s:RunEdit(a:state, a:tmp, a:job)