@@ -67,6 +67,9 @@ func! neovim_rpc#jobstart(cmd,...)
6767let l: opts= a: 1
6868endif
6969
70+ let l: opts [' _close' ]= 0
71+ let l: opts [' _exit' ]= 0
72+
7073let l: real_opts= {' mode' :' raw' }
7174if has_key (l: opts ,' detach' )&& l: opts [' detach' ]
7275let l: real_opts [' stoponexit' ]= ' '
@@ -79,6 +82,7 @@ func! neovim_rpc#jobstart(cmd,...)
7982let l: real_opts [' err_cb' ]= function (' neovim_rpc#_on_stderr' )
8083endif
8184let l: real_opts [' exit_cb' ]= function (' neovim_rpc#_on_exit' )
85+ let l: real_opts [' close_cb' ]= function (' neovim_rpc#_on_close' )
8286
8387let l: job= job_start (a: cmd ,l: real_opts )
8488let l: jobid= ch_info (l: job )[' id' ]
@@ -139,13 +143,27 @@ endfunc
139143func ! neovim_rpc#_on_exit (job,status)
140144let l: jobid= ch_info (a: job )[' id' ]
141145let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
142- unlet g: _neovim_rpc_jobs [l: jobid ]
146+ let l: opts [' _exit' ]= 1
147+ " cleanup when both close_cb and exit_cb is called
148+ if l: opts [' _close' ]&& l: opts [' _exit' ]
149+ unlet g: _neovim_rpc_jobs [l: jobid ]
150+ endif
143151if has_key (l: opts ,' on_exit' )
144152" convert to neovim style function call
145153call call (l: opts [' on_exit' ],[l: jobid ,a: status ,' exit' ],l: opts )
146154endif
147155endfunc
148156
157+ func ! neovim_rpc#_on_close (job)
158+ let l: jobid= ch_info (a: job )[' id' ]
159+ let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
160+ let l: opts [' _close' ]= 1
161+ " cleanup when both close_cb and exit_cb is called
162+ if l: opts [' _close' ]&& l: opts [' _exit' ]
163+ unlet g: _neovim_rpc_jobs [l: jobid ]
164+ endif
165+ endfunc
166+
149167func ! neovim_rpc#_callback ()
150168execute s: py .' neovim_rpc_server.process_pending_requests()'
151169endfunc