summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-03-09 20:22:02 +0000
committerw0rp <devw0rp@gmail.com>2017-03-09 20:22:02 +0000
commitfc072a07727865b664dbaaad582b20c0d48c904e (patch)
tree6ff54b22a8fa9c978d97730592f1ed51e7ff0efb /autoload
parentad49846a48beab2ed7fe58a799e6a53e99086bb2 (diff)
downloadale-fc072a07727865b664dbaaad582b20c0d48c904e.zip
Get milliseconds timestamps without system() calls for tests
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/engine.vim6
-rw-r--r--autoload/ale/util.vim10
2 files changed, 13 insertions, 3 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 1ab9c8b2..63362785 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -644,7 +644,7 @@ 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:start_time = system('date +%s%3N') + 0
+ let l:start_time = ale#util#ClockMilliseconds()
if l:start_time == 0
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
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
" 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
" 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)
if l:new_deadline <= 0
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index bf00051a..600717db 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -134,3 +134,13 @@ function! ale#util#InSandbox() abort
return 0
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