add async#job#pid() (#28)

* add async#job#pid()

* fix type check

* added link to jobpid
This commit is contained in:
Prabir Shrestha
2019-01-13 16:09:44 -08:00
committed by GitHub
parent 0521409a9a
commit ff9177ccae
3 changed files with 25 additions and 1 deletions
-1
View File
@@ -14,6 +14,5 @@ script:
- pip install --user --upgrade vim-vint pathlib enum34 typing
- python --version
- vim --version
- vint --version
- vint autoload
- /tmp/vim-themis/bin/themis --reporter dot
+4
View File
@@ -27,6 +27,9 @@ else
echom 'job failed to start'
endif
" If you want to get the process id of the job
let pid = async#job#pid(jobid)
" If you want to wait the job:
call async#job#wait([jobid], 5000) " timeout: 5 sec
@@ -43,6 +46,7 @@ APIs are based on neovim's job control APIs.
* [jobstart()](https://neovim.io/doc/user/eval.html#jobstart%28%29)
* [jobstop()](https://neovim.io/doc/user/eval.html#jobstop%28%29)
* [jobwait()](https://neovim.io/doc/user/eval.html#jobwait%28%29)
* [jobpid()](https://neovim.io/doc/user/eval.html#jobpid%28%29)
## Embedding
+21
View File
@@ -246,6 +246,23 @@ function! s:job_wait(jobids, timeout) abort
return l:ret
endfunction
function! s:job_pid(jobid) abort
if !has_key(s:jobs, a:jobid)
return 0
endif
let l:jobinfo = s:jobs[a:jobid]
if l:jobinfo.type == s:job_type_nvimjob
return jobpid(a:jobid)
elseif l:jobinfo.type == s:job_type_vimjob
let l:vimjobinfo = job_info(a:jobid)
if type(l:vimjobinfo) == type({}) && has_key(l:vimjobinfo, 'process')
return l:vimjobinfo['process']
endif
endif
return 0
endfunction
" public apis {{{
function! async#job#start(cmd, opts) abort
return s:job_start(a:cmd, a:opts)
@@ -263,4 +280,8 @@ function! async#job#wait(jobids, ...) abort
let l:timeout = get(a:000, 0, -1)
return s:job_wait(a:jobids, l:timeout)
endfunction
function! async#job#pid(jobid) abort
return s:job_pid(a:jobid)
endfunction
" }}}