Get milliseconds timestamps without system() calls for tests
This commit is contained in:
parent
ad49846a48
commit
fc072a0772
2 changed files with 13 additions and 3 deletions
|
@ -644,7 +644,7 @@ endfunction
|
||||||
" The time taken will be a very rough approximation, and more time may be
|
" The time taken will be a very rough approximation, and more time may be
|
||||||
" permitted than is specified.
|
" permitted than is specified.
|
||||||
function! ale#engine#WaitForJobs(deadline) abort
|
function! ale#engine#WaitForJobs(deadline) abort
|
||||||
let l:start_time = system('date +%s%3N') + 0
|
let l:start_time = ale#util#ClockMilliseconds()
|
||||||
|
|
||||||
if l:start_time == 0
|
if l:start_time == 0
|
||||||
throw 'Failed to read milliseconds from the clock!'
|
throw 'Failed to read milliseconds from the clock!'
|
||||||
|
@ -664,7 +664,7 @@ function! ale#engine#WaitForJobs(deadline) abort
|
||||||
|
|
||||||
for l:job in l:job_list
|
for l:job in l:job_list
|
||||||
if job_status(l:job) ==# 'run'
|
if job_status(l:job) ==# 'run'
|
||||||
let l:now = system('date +%s%3N') + 0
|
let l:now = ale#util#ClockMilliseconds()
|
||||||
|
|
||||||
if l:now - l:start_time > a:deadline
|
if l:now - l:start_time > a:deadline
|
||||||
" Stop waiting after a timeout, so we don't wait forever.
|
" Stop waiting after a timeout, so we don't wait forever.
|
||||||
|
@ -697,7 +697,7 @@ function! ale#engine#WaitForJobs(deadline) abort
|
||||||
|
|
||||||
if l:has_new_jobs
|
if l:has_new_jobs
|
||||||
" We have to wait more. Offset the timeout by the time taken so far.
|
" We have to wait more. Offset the timeout by the time taken so far.
|
||||||
let l:now = system('date +%s%3N') + 0
|
let l:now = ale#util#ClockMilliseconds()
|
||||||
let l:new_deadline = a:deadline - (l:now - l:start_time)
|
let l:new_deadline = a:deadline - (l:now - l:start_time)
|
||||||
|
|
||||||
if l:new_deadline <= 0
|
if l:new_deadline <= 0
|
||||||
|
|
|
@ -134,3 +134,13 @@ function! ale#util#InSandbox() abort
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Get the number of milliseconds since some vague, but consistent, point in
|
||||||
|
" the past.
|
||||||
|
"
|
||||||
|
" This function can be used for timing execution, etc.
|
||||||
|
"
|
||||||
|
" The time will be returned as a Number.
|
||||||
|
function! ale#util#ClockMilliseconds() abort
|
||||||
|
return float2nr(reltimefloat(reltime()) * 1000)
|
||||||
|
endfunction
|
||||||
|
|
Reference in a new issue