lev.fd_reader

lev

fd_reader(fd) -> reader

Wrap an arbitrary fd for cooperative reads on the event loop

Returns a reader for fd (e.g. stdin, fd 0) that integrates with the event loop. :read(maxlen, opts) yields the current coroutine until at least one byte is available, returning the bytes, or nil,"closed" on EOF, or nil,"cancelled"/err. :read_available(maxlen) drains all currently-readable bytes without yielding.

The fd must be in non-blocking mode (see set_nonblocking) and must be epoll-able (a TTY or pipe, not a regular file). Only one coroutine may wait on a given fd at a time.