Created
March 23, 2025 04:18
An example refinement method like `IO.pipe`'s block form but with no buffering.
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
class IO | |
module UnbufferedPipe | |
refine IO.superclass do | |
def unbuffered_pipe(*, **) | |
IO.pipe(*, **) do |read_io, write_io| | |
read_io.sync = true | |
write_io.sync = true | |
yield read_io, write_io | |
end | |
end | |
end | |
end | |
end | |
## | |
# Usage example | |
using IO::UnbufferedPipe | |
IO.unbuffered_pipe do |read_io, write_io| | |
write_io << "hola\n" | |
read_io.gets | |
end | |
#=> "hola\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment