diff options
Diffstat (limited to 'runtime/doc/job_control.txt')
-rw-r--r-- | runtime/doc/job_control.txt | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/runtime/doc/job_control.txt b/runtime/doc/job_control.txt index f381d5ad66..000409597f 100644 --- a/runtime/doc/job_control.txt +++ b/runtime/doc/job_control.txt @@ -13,7 +13,7 @@ Nvim's facilities for job control *job-control* 1. Introduction *job-control-intro* Job control is a simple way to perform multitasking in vimscript. Wikipedia -contains a more generic/detailed description: +contains a more generic/detailed description: "Job control in computing refers to the control of multiple tasks or Jobs on a computer system, ensuring that they each have access to adequate resources to @@ -27,8 +27,8 @@ control multiple processes without blocking the current Nvim instance. Nvim's job control was designed to be simple and familiar to vimscript programmers, instead of being very powerful but complex. Unlike Vim's -facilities for calling with external commands, job control does not depend -on installed shells, calling OS functions for process management directly. +facilities for calling with external commands, job control does not depend on +available shells, instead relying on OS functionality for process management. Internally, Nvim job control is powered by libuv, which has a nice cross-platform API for managing processes. See https://github.com/libuv/libuv @@ -43,8 +43,8 @@ event. The best way to understand is with a complete example: > set nocp let job1 = jobstart('shell1', 'bash') - let job2 = jobstart('shell2', 'bash', ['-c', 'for ((i = 0; i < 10; i++)); do echo -n hello $i!; sleep 2; done']) - + let job2 = jobstart('shell2', 'bash', ['-c', 'for ((i = 0; i < 10; i++)); do echo hello $i!; sleep 1; done']) + function JobHandler() if v:job_data[1] == 'stdout' let str = 'shell '. v:job_data[0].' stdout: '.join(v:job_data[2]) @@ -53,27 +53,27 @@ event. The best way to understand is with a complete example: else let str = 'shell '.v:job_data[0].' exited' endif - + call append(line('$'), str) endfunction - + au JobActivity shell* call JobHandler() < -To test the above, copy it to the ~/jobcontrol.vim file and start with a clean +To test the above, copy it to the file ~/jobcontrol.vim and start with a clean nvim instance: - > - nvim -u NONE -S ~/jobcontrol.vim +> + nvim -u NONE -S ~/jobcontrol.vim < Here's what is happening: -- Two bash instances are spawned by |jobstart()| and their stdin/stdout/stderr - are connected to nvim. -- The first shell is idle, waiting to read commands from it's stdin -- The second shell is passed the -c option to execute a command and exit. In - our case, the command is a for loop that will print numbers and exit after - a while. -- The JobHandler function is called by the JobActivity autocommand(notice how - the shell* pattern matches the `shell1` and `shell2` names passed to +- Two bash instances are spawned by |jobstart()| with their stdin/stdout/stderr + connected to nvim. +- The first shell is idle, waiting to read commands from its stdin. +- The second shell is started with the -c argument, causing it to execute a + command then exit. In this case, the command is a for loop that will print 0 + through 9 then exit. +- The |JobHandler()| function is called by the `JobActivity` autocommand (notice + how the shell* pattern matches the names `shell1` and `shell2` passed to |jobstart()|), and it takes care of displaying stdout/stderr received from the shells. - The v:job_data is an array set by the JobActivity event. It has the @@ -86,16 +86,16 @@ Here's what is happening: To send data to the job's stdin, one can use the |jobsend()| function, like this: > - :call jobsend(job1, 'ls\n') - :call jobsend(job1, 'invalid-command\n') - :call jobsend(job1, 'exit\n') + :call jobsend(job1, "ls\n") + :call jobsend(job1, "invalid-command\n") + :call jobsend(job1, "exit\n") < A job may be killed at any time with the |jobstop()| function: > :call jobstop(job1) < -When |jobstop()| is called, it will send `SIGTERM` to the job. If a job -doesn't exit after a while, `SIGKILL` will be sent. - +When |jobstop()| is called, `SIGTERM` will be sent to the job. If a job does +not exit after 2 seconds, `SIGKILL` will be sent. + ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: |