Skip to content

Instantly share code, notes, and snippets.

@hauleth
Created November 5, 2017 14:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hauleth/0cce9962ffc9a09b3893d53dbcd3abf9 to your computer and use it in GitHub Desktop.
Save hauleth/0cce9962ffc9a09b3893d53dbcd3abf9 to your computer and use it in GitHub Desktop.
Minimal async runner
func! s:populate(file, cmd) abort
unlet! t:job
try
exe 'cgetfile '.a:file
finally
call setqflist([], 'a', {'title': a:cmd})
endtry
endfunc
func! AsyncDo(...) abort
if exists('t:job')
echoerr 'There is currently running job, just wait'
return
endif
call setqflist([], 'r')
let tmp = tempname()
let cmd = join(a:000)
let g:qf_quickfix_titles = []
if has('nvim')
let t:job = jobstart([&sh, &shcf, printf(cmd.&srr, tmp)], {
\ 'on_exit': {id, data, event -> s:populate(tmp, cmd)}
\ })
else
let t:job = job_start([&sh, &shcf, printf(cmd.&srr, tmp)], {
\ 'in_io': 'null','out_io': 'null','err_io': 'null',
\ 'exit_cb': {job, result -> s:populate(tmp, cmd)}
\ })
endif
endfunc
com! -nargs=+ AsyncDo call AsyncDo(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment