wait_readable
fn wait_readable(Stream s) -> Result<unit, IoError> Import
Source: use io::{wait_readable}; compiler/src/builtin_docs/io.hy Waits until s is readable.
Returns at once when data (or end of file) is already available.
Inside a task only that task waits while the others run; elsewhere the
program waits. Returns Err(IoError::TimedOut) when the stream’s read
timeout passes and Err(IoError::AlreadyClosed) on a closed stream.
await_readable is an older name for the same function.
Parameters#
| Name | Type |
|---|---|
s | Stream |
Returns#
Result<unit, IoError>
Examples#
use io::{read, wait_readable, IoError};
use io::net::tcp::{connect, listen, local_addr};
use io::sync::{accept_wait, write_all};
use string::{to_bytes};
use tests::assert;
fn run() -> Result<Option<int>, IoError> {
let listener = listen("127.0.0.1", 0)?;
let (_, port) = local_addr(listener)?;
let client = connect("127.0.0.1", port)?;
let server = accept_wait(listener)?;
write_all(client, to_bytes("ping"))?;
wait_readable(server)?;
return read(server, to_bytes("........"))?;
}
fn main() {
let n = match run() {
Result::Ok(Option::Some(n)) => n,
default => 0,
};
assert!(n == 4);
}
See also#
io::await_readablestdin: Returns a new stream on the process’s standard input.stdout: Returns a new stream on the process’s standard output.stderr: Returns a new stream on the process’s standard error.capture_begin: Starts keeping this thread’s stdout and stderr writes in memory instead of writing them, until the matchingcapture_end().capture_end: Ends the innermostcapture_begin()and returns what it kept, as(stdout, stderr).open: Opens the file atpathwithmodeand returns a stream on it.close: Closess.