mirror of
https://github.com/prabirshrestha/async.vim.git
synced 2026-05-30 11:18:50 +02:00
add async#job#pid() (#28)
* add async#job#pid() * fix type check * added link to jobpid
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
" }}}
|
||||
|
||||
Reference in New Issue
Block a user