Saturday, May 6, 2017

job_start callback : retrieve calling object funcref

Hi,

I'm writing some little script to start jobs from serial or parallel way.

In the case of serial job's starts, I need to increment job current index each time the current job is finished.

The index is in the caller object (dict and funcref mechanism).

From the callback func, how can I retrieve ref of my main object caller to increment this index ?

Thank you
Niva

Sumup of code :

________ dict object ref

let s:ijob=0
let cmdlauncher = {}

function! cmdlauncher#new() "{{{

let obj = {}
let obj._cmds = [] " Job command
let obj._jobs = [] " Job object
let obj._ijob = s:ijob " Job index

function! obj.add_cmd(cmd) "{{{
call add(self._cmds, a:cmd)
endfunction "}}}
function! obj.startjob() "{{{
let cmd = 'cmd /k '.self._cmds[self._ijob]

call add (self._jobs, job_start(cmd, {
\ 'exit_cb' : 'cmdlauncher#exit_cb',
\ 'close_cb' : 'cmdlauncher#close_cb',
\ 'callback' : 'cmdlauncher#callback'
\ })
\)
let ch = job_getchannel(self._jobs[-1])

endfunction "}}}


return obj
endfunction "}}}

function! cmdlauncher#exit_cb(job, status) "{{{
try
echomsg "job exit with : ".string(a:job.' '.a:status)
" echomsg get("cmdlauncher", "name") "<< KO
catch E716
" No-op if data isn't ready
endtry
endfunction "}}}


________ caller


" plan cmds
let x = cmdlauncher#new()

call x.add_cmd(cmd1)
call x.add_cmd(cmd2)

call x.startjob()

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: