comparison runtime/doc/channel.txt @ 10422:e664ee056a84 v8.0.0105

commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Nov 29 21:54:44 2016 +0100 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().
author Christian Brabandt <cb@256bit.org>
date Tue, 29 Nov 2016 22:00:05 +0100
parents 368468ef35cf
children acfc83aca8ee
comparison
equal deleted inserted replaced
10421:474ff13f3ec3 10422:e664ee056a84
416 let output = ch_read(channel) 416 let output = ch_read(channel)
417 This uses the channel timeout. To read without a timeout, just get any 417 This uses the channel timeout. To read without a timeout, just get any
418 message that is available: > 418 message that is available: >
419 let output = ch_read(channel, {'timeout': 0}) 419 let output = ch_read(channel, {'timeout': 0})
420 When no message was available then the result is v:none for a JSON or JS mode 420 When no message was available then the result is v:none for a JSON or JS mode
421 channels, an empty string for a RAW or NL channel. 421 channels, an empty string for a RAW or NL channel. You can use |ch_canread()|
422 to check if there is something to read.
423
424 Note that when there is no callback message are dropped. To avoid that add a
425 close callback to the channel.
422 426
423 To read all output from a RAW channel that is available: > 427 To read all output from a RAW channel that is available: >
424 let output = ch_readraw(channel) 428 let output = ch_readraw(channel)
425 To read the error output: > 429 To read the error output: >
426 let output = ch_readraw(channel, {"part": "err"}) 430 let output = ch_readraw(channel, {"part": "err"})
462 it like this: > 466 it like this: >
463 func MyHandler(channel, msg) 467 func MyHandler(channel, msg)
464 468
465 Without the handler you need to read the output with |ch_read()| or 469 Without the handler you need to read the output with |ch_read()| or
466 |ch_readraw()|. You can do this in the close callback, see |read-in-close-cb|. 470 |ch_readraw()|. You can do this in the close callback, see |read-in-close-cb|.
471
472 Note that if the job exits before you read the output, the output may be lost.
473 This depends on the system (on Unix this happens because closing the write end
474 of a pipe causes the read end to get EOF). To avoid this make the job sleep
475 for a short while before it exits.
467 476
468 Note that if the job exits before you read the output, the output may be lost. 477 Note that if the job exits before you read the output, the output may be lost.
469 This depends on the system (on Unix this happens because closing the write end 478 This depends on the system (on Unix this happens because closing the write end
470 of a pipe causes the read end to get EOF). To avoid this make the job sleep 479 of a pipe causes the read end to get EOF). To avoid this make the job sleep
471 for a short while before it exits. 480 for a short while before it exits.