Bram Moolenaar wrote:
> Patch 8.0.0105
> Problem:    When using ch_read() with zero timeout, can't tell the difference
>             between reading an empty line and nothing available.
> Solution:   Add ch_canread().
> Files:      src/evalfunc.c, src/channel.c, src/proto/channel.pro,
>             src/testdir/test_channel.vim, src/testdir/shared.vim,
>             runtime/doc/eval.txt, runtime/doc/channel.txt

This is fabulous, thanks for ch_canread()
However, a lot of messages are still dropped in spite of adding a sleep before 
exiting:

-----------------------------
timerjob.vim
-----------------------------
function! MyTimer(id)
    let ch = job_getchannel(g:job)
    let st = ch_status(ch)
    if st == "fail" || st == "closed"
        return
    endif
    if ch_canread(ch)
        let text = ch_read(ch, {'timeout':0})
        caddexpr text
        cbottom
    endif
endfunc

" according to channel.txt, add a close callback
function! MyClose(channel)
    caddexpr "[channel closed]"
    cbottom
endfunc

copen 8
cexpr "[python output]"
wincmd k

let cmd = ['/usr/bin/python', 'timerjob.py']
let opt = {"out_io": "pipe", "err_io": "out", "close_cb": "MyClose"}

let job = job_start(cmd, opt)
let timer = timer_start(10, "MyTimer", {"repeat":-1})

-------------------------
timerjob.py
-------------------------
#! /usr/bin/env python2
import sys, time

for i in xrange(80000):
    sys.stdout.write('timer job: this is line %d\n'%(i))
    sys.stdout.flush()

# as channel.txt said, we need a sleep here
time.sleep(1)

-------------------------
output in quickfix
-------------------------
|| [python output]        
|| timer job: this is line 0
|| timer job: this is line 1
|| timer job: this is line 2
|| timer job: this is line 3
|| timer job: this is line 4
|| timer job: this is line 5
.....
|| timer job: this is line 57
|| timer job: this is line 58
|| timer job: this is line 59
|| timer job: this is line 60
|| timer job: this is line 61
|| [channel closed]

Only 62 messages have been received, almost 80000 - 62 = 79938 messages have 
been dropped.

I can sleep longer in timerjob.py, but I can't add a single sleep if I start 
grep as a job. And I can't decide how long should I sleep to avoid dropping.




-- 
-- 
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