From ff9177ccaea51dba67a37a6b58b623e6a2a2c610 Mon Sep 17 00:00:00 2001 From: Prabir Shrestha Date: Sun, 13 Jan 2019 16:09:44 -0800 Subject: [PATCH] add async#job#pid() (#28) * add async#job#pid() * fix type check * added link to jobpid --- .travis.yml | 1 - README.md | 4 ++++ autoload/async/job.vim | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7dd9212..5d3dfd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index e66ef98..f576c06 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/autoload/async/job.vim b/autoload/async/job.vim index 2d75531..3735df5 100644 --- a/autoload/async/job.vim +++ b/autoload/async/job.vim @@ -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 " }}}