close
fn close(Stream s) -> Result<unit, IoError> Import
Source: use io::{close}; compiler/src/builtin_docs/io.hy Closes s.
Closing an attached stream calls its package shutdown and free
hooks first, and wakes any task waiting on it. Closing twice returns
Err(IoError::AlreadyClosed). A stream that is never closed is closed
when the garbage collector drops it.
Parameters#
| Name | Type |
|---|---|
s | Stream |
Returns#
Result<unit, IoError>
Examples#
use io::{close, stdout, IoError};
use tests::assert;
let s = stdout();
let first = match close(s) {
Result::Ok(_) => true,
Result::Err(_) => false,
};
let second = match close(s) {
Result::Err(IoError::AlreadyClosed) => true,
default => false,
};
assert!(first && second);
See also#
stdin: 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.read: Reads bytes fromsinto the front ofbufwithout waiting.write: Writes bytes frombuftoswithout waiting and returns how many were written.