-
-
Save awfulcooking/2bb0e04b5316f80436dabffca8da6811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ReadlineNonblock | |
def readline_nonblock | |
@readline_nonblock_buf ||= "" | |
until @readline_nonblock_buf[-1] == "\n" | |
# read_nonblock may raise e.g. IO::WaitReadable, or EOFError | |
@readline_nonblock_buf << read_nonblock(1) | |
end | |
complete_line = @readline_nonblock_buf | |
@readline_nonblock_buf = "" | |
return complete_line | |
end | |
end | |
::IO.include ReadlineNonblock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment