Function in io compiler

close

fn close(Stream s) -> Result<unit, IoError>
Import
use io::{close};
Source: 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#

NameType
sStream

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 matching capture_end().
  • capture_end: Ends the innermost capture_begin() and returns what it kept, as (stdout, stderr).
  • open: Opens the file at path with mode and returns a stream on it.
  • read: Reads bytes from s into the front of buf without waiting.
  • write: Writes bytes from buf to s without waiting and returns how many were written.
↑ ↓ navigate ↵ open