> On 26 Apr 2016, at 8:38 pm, Bram Moolenaar <[email protected]> wrote:
> 
> You can now use ch_status() for that.  If it returns "open" or
> "buffered" there may be more to read.  When "closed" then it's done.
> 
> I have added this example in the help:
> 
>       func! CloseHandler(channel)
>         while ch_status(a:channel) == 'buffered'
>           echomsg ch_read(a:channel)
>         endwhile
>       endfunc
>       let job = job_start(command, {'close_cb': 'CloseHandler'})

Should the condition be `while ch_status(a:channel) == 'buffered' || 
ch_status(a:channel) == 'open'` as per the description?

I upgraded to 7.4.1795 and tried out the example as is.

I couldn't find the example in the help.

Every few callbacks the screen needed a `:redraw!` to:

- display the correct signs (my handler updates them)
- display the cursor in the correct position (getpos('.') showed the right 
coordinates but the cursor was displayed elsewhere).

I haven't been able to reproduce this consistently.  I tried adding a 
`redraw`/`redraw!` as the last line of my handler but it didn't make any 
difference.

Every few dozen callbacks `ch_read(a:channel)` threw an E906 error, though 
again I'm not able to reproduce it consistently.  Perhaps there is a race 
condition where the channel is closed between checking its status and reading 
from it?  I modified my handler to:

    function! CloseHandler(channel)
      let output = ''
      try
        while ch_status(a:channel) == 'buffered'
        let line = ch_read(a:channel)
        if line !=# 'DETACH'
          let output .= line."\n"
        endif
      endwhile
      echom output
    endfunction

...which seemed to work well, at least until Vim crashed:

    Vim: Caught deadly signal SEGV
    Vim(85664,0x7fff7a952000) malloc: *** error for object 0x7ff2106739e8: 
incorrect checksum for freed object - object was probably modified after being 
freed.
                                      *** set a breakpoint in 
malloc_error_break to debug
                                                                                
       Vim: Finished.
    Vim: Double signal, exiting
    Abort trap: 6

I don't know how to set a breakpoint in malloc_error_break so I wasn't able to 
debug this, sorry.  When it happened there was nothing unusual in the channel 
log.

I also implemented my job_start using an out_cb handler again instead of a 
close_cb handler.  The occasional-missing-callback problem has disappeared and 
it all worked perfectly.  Thanks!

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui