From 02e42feeaafde1cb2677e798d898c58cc4c40a26 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 17 Oct 2016 23:43:31 +0100 Subject: [PATCH] Make the function for waiting for jobs to complete more reliable. --- autoload/ale/engine.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 2df9738..5cdcd7c 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -262,7 +262,12 @@ endfunction " The time taken will be a very rough approximation, and more time may be " permitted than is specified. function! ale#engine#WaitForJobs(deadline) abort - let l:time_ticked = 0 + let l:start_time = system('date +%s%3N') + 0 + + if l:start_time == 0 + throw 'Failed to read milliseconds from the clock!' + endif + let l:job_list = [] for l:job_id in keys(s:job_info_map) @@ -276,17 +281,24 @@ function! ale#engine#WaitForJobs(deadline) abort for l:job in l:job_list if job_status(l:job) ==# 'run' - if l:time_ticked > a:deadline + let l:now = system('date +%s%3N') + 0 + + if l:now - l:start_time > a:deadline " Stop waiting after a timeout, so we don't wait forever. throw 'Jobs did not complete on time!' endif " Wait another 10 milliseconds - let l:time_ticked += 10 let l:should_wait_more = 1 sleep 10ms break endif endfor endwhile + + " Sleep for a small amount of time after all jobs finish. + " This seems to be enough to let handlers after jobs end run, and + " prevents the occasional failure where this function exits after jobs + " end, but before handlers are run. + sleep 10ms endfunction