*vital/Deprecated.ProcessManager.txt*	process manager with vimproc.

Maintainer: ujihisa <ujihisa at gmail com>

==============================================================================
CONTENTS			*Vital.Deprecated.ProcessManager-contents*

INTRODUCTION			|Vital.Deprecated.ProcessManager-introduction|
  USAGE				|Vital.Deprecated.ProcessManager-usage|
  PRINCIPLE			|Vital.Deprecated.ProcessManager-principle|
INTERFACE			|Vital.Deprecated.ProcessManager-interface|
  FUNCTIONS			  |Vital.Deprecated.ProcessManager-functions|
CONFIG				|Vital.Deprecated.ProcessManager-config|



==============================================================================
INTRODUCTION			*Vital.Deprecated.ProcessManager-introduction*

Note this module is going to be deprecated. Use |Vital.ConcurrentProcess|
instead.

*Vital.Deprecated.ProcessManager* is a Vim's process manager library, powered by
|vimproc|.  This manager stores external processes ran by this library, and
provide higher layer synchronous non-blocking read/write interface.

Note that this library doesn't work on Vim without vimproc; vimproc is
required.


==============================================================================
USAGE				*Vital.Deprecated.ProcessManager-usage*
>
	let P = V.import('Deprecated.ProcessManager')
	if !P.is_available() " please always check if it's available.
	  throw "omg"
	endif
	call P.touch('i', 'clojure-1.5') " creates a process that runs clojure
	" read the stdout/stderr and wait until the process's output stays
	" same for 2.0 sec.
	echo P.read_wait('i', 2.0, [])
	call P.writeln('i', '(+ 2 3)')
	" read the stdout/stderr and wait until the process's output stays
	" same for 0.05 sec.
	echo P.read('i', []) " ["5\nuser=>", '', 'timedout']
	" kills the process, and let Deprecated.ProcessManager forget it.
	echo P.term('i') " gracefully stop the process
	echo P.status('i') " 'inactive'
<

>
	" An alternative way with label
	function! s:f(x)
	  let t = P.touch('my-scala', 'scala')
	  if t ==# 'new'
	    " wait for longer time to make sure scala runs, since scala is
	    " really slow to be ready.
	    let [out, err, type] = P.read_wait('my-scala', 2.0, ['scala> '])
	    if type ==# 'timedout'
	      throw 'omg it took too much time'
	    endif
	  endif
	  call P.writeln('my-scala', a:x)
	  let [out, err, type] = P.read('my-scala', ['scala> '])
	  if type ==# 'timedout'
	    throw 'something easy to do please'
	  elseif type ==# 'inactive'
	    throw 'scala had died...!'
	  endif
	  return out
	endfunction

	echo s:f('1 + 2') "=> '3' but slow
	echo s:f('2 + 3') "=> '5' and fast!
<

MEMO
* touch is almost idempotent
* read's out split needs \r as well for windows

==============================================================================
PRINCIPLE			*Vital.Deprecated.ProcessManager-principle*

* Nonblocking
  * blocking APIs should have verbose name to discourage developers to use
* Synchronous (asynchronous in Vim always makes trouble)
* Don't show lower layer too much easily, but don't hide completely. No
  perfect abstraction exists in the world.
* Avoid tricky specification. Function name and behaviour itself should
  explain what it does.
>
==============================================================================
INTERFACE			*Vital.Deprecated.ProcessManager-interface*

------------------------------------------------------------------------------
FUNCTIONS			*Vital.Deprecated.ProcessManager-functions*

touch({label}, {cmd})		*Vital.Deprecated.ProcessManager.touch()*
	Returns a string which is either "existing" or "new".
	TODO

state({label})			*Vital.Deprecated.ProcessManager.state()*
	Returns either "undefined", "inactive", "reading", or "idle".

==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl
