Skip to content

Commit e165c1d

Browse files
committed
System.AsyncProcess: Added timeout mechanism in System.AsyncProcess.
1 parent 63833da commit e165c1d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

autoload/vital/__vital__/System/AsyncProcess.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ endif
7979
" out_cb: function(stdout_msg), " call per line
8080
" err_cb: function(stderr_msg), " call per line
8181
" exit_cb: function(exit_code), " call on exit
82+
" timeout: Number(ms),
8283
" }
8384
function! s:execute(command, options) abort
8485
if !type(a:options) is s:TYPE_DICT
@@ -112,6 +113,12 @@ function! s:execute(command, options) abort
112113

113114
let job_id = jobstart([&shell] + args, options)
114115

116+
if has_key(a:options, 'timeout')
117+
if a:options.timeout > 0
118+
call timer_start(a:options.timeout, {-> jobstop(job_id)})
119+
endif
120+
endif
121+
115122
return {
116123
\ 'stop': function('jobstop', [job_id]),
117124
\ }
@@ -123,6 +130,12 @@ function! s:execute(command, options) abort
123130

124131
let job = job_start([&shell] + args, options)
125132

133+
if has_key(a:options, 'timeout')
134+
if a:options.timeout > 0
135+
call timer_start(a:options.timeout, {-> job_stop(job)})
136+
endif
137+
endif
138+
126139
return {
127140
\ 'stop': function('job_stop', [job]),
128141
\ }

0 commit comments

Comments
 (0)