From 4b785f69c0616dba5d3f38e8ce4b5398cec89407 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 29 Nov 2016 21:54:44 +0100 Subject: 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(). --- runtime/doc/channel.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'runtime/doc/channel.txt') diff --git a/runtime/doc/channel.txt b/runtime/doc/channel.txt index 73105986f6..2c3f837300 100644 --- a/runtime/doc/channel.txt +++ b/runtime/doc/channel.txt @@ -418,7 +418,11 @@ This uses the channel timeout. To read without a timeout, just get any message that is available: > let output = ch_read(channel, {'timeout': 0}) When no message was available then the result is v:none for a JSON or JS mode -channels, an empty string for a RAW or NL channel. +channels, an empty string for a RAW or NL channel. You can use |ch_canread()| +to check if there is something to read. + +Note that when there is no callback message are dropped. To avoid that add a +close callback to the channel. To read all output from a RAW channel that is available: > let output = ch_readraw(channel) @@ -470,6 +474,11 @@ This depends on the system (on Unix this happens because closing the write end of a pipe causes the read end to get EOF). To avoid this make the job sleep for a short while before it exits. +Note that if the job exits before you read the output, the output may be lost. +This depends on the system (on Unix this happens because closing the write end +of a pipe causes the read end to get EOF). To avoid this make the job sleep +for a short while before it exits. + The handler defined for "out_cb" will not receive stderr. If you want to handle that separately, add an "err_cb" handler: > let job = job_start(command, {"out_cb": "MyHandler", -- cgit v1.2.3