close_cb or exit_cb?

20 views
Skip to first unread message

Andrew Stewart

unread,
Nov 10, 2020, 6:59:31 AM11/10/20
to vim_dev
Hello!

I have managed to confuse myself over whether I should use close_cb or exit_cb to detect when I have received all the data from an external command's stdout.

I want to run "ps -axco command" in a job, gather the results from stdout, and then do something with the results.

My job_start() specifies an out_cb which is called with each line from stdout and accumulates the lines in a list.  My question is: what is the recommended way to know when I have all the data?

I have read the docs for exit_cb and close_cb many times but I can't figure it out.

exit_cb sounds right because it is called when the job ends; but apparently callbacks can still be called after exit_cb due to buffering, which seems to rule out exit_cb as a way of knowing when things are finished.  

close_cb is called when the channel is closed – but this seems like the wrong level of abstraction; I don't care about the channel.  Anyway, on the plus side, once close_cb is called no more data-handling callbacks will be called.  But it turns out I can't rely on close_cb because it isn't always called; in fact I am trying to debug a situation where a job from one plugin prevents another plugin's job's close_cb from being called.

I have looked at all the docs and read the job/channel test code, but I'm still not sure what the recommended way is for this kind of job.

Any help would be much appreciated!

Yours,
Andrew Stewart

bo...@airbladesoftware.com

unread,
Nov 16, 2020, 9:22:07 AM11/16/20
to vim_dev
Further investigation of the situation where close_cb wasn't called showed that the channel had got stuck in a "pre-closing" state, and only ctrl-c would allow it to actually close.  Here's a gist with code and channel logging:


Switching from a close_cb to an exit_cb sidesteps this problem for me.

However, I still don't know what the "best practice" is: close_cb or exit_cb?

Yours,
Andrew Stewart

Reply all
Reply to author
Forward
0 new messages