-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC wait() support for GenericIOBuffer/PipeBuffer #23391
Conversation
This proposal adds `wait(io::GenericIOBuffer)` to wait for something to be written to the buffer and modifies `eof(io::GenericIOBuffer)` to be false if `io.writeable` is true. This allows an async producer / consumer pattern like this: ```julia io = PipeBuffer() @async while true if done close(io) end println(io, now()) sleep(1) end while !eof(io) wait(io) println(String(readavailable(io))) end ``` @quinnj has a FIFOBuffer class in HTTP.jl that attempts to do something like this, but isn't working 100% yet: JuliaWeb/HTTP.jl#74 . It seems to me that reading and writing from a buffered pipe is a generally useful and a good thing to have in Base. Note: I haven't tried to compile or run the code in this PR. If I there is support for a change like this, I'll make sure it works and add tests etc.
This already exists. See |
@vtjnash can you elaborate on that, pls? |
The requested / proposed functionality is already implemented and exported from Base. |
@vtjnash that's great! Is there any point in having See also #23398 |
|
@quinnj Any reason you couldn't use @vtjnash whats the deal with |
I definitely took inspiration from |
Is there any reason that something like the The current julia> io = PipeBuffer()
julia> write(io, "Hello")
julia> close(io)
julia> readstring(io)
ERROR: ArgumentError: read failed, IOBuffer is not readable
julia> take!(io)
ERROR: ArgumentError: read failed, IOBuffer is not readable vs julia> io = BufferStream()
julia> write(io, "Hello")
julia> close(io)
julia> readstring(io)
"Hello" |
@quinnj as far as I understand, e.g. julia> io = BufferStream()
BufferStream() bytes waiting:0, isopen:true
julia> @async while true
println(io, now())
sleep(1)
end
Task (runnable) @0x000000011c52c250
julia> while !eof(io)
println(String(readavailable(io)))
end
2017-08-23T07:09:15.929
2017-08-23T07:09:16.935
2017-08-23T07:09:17.939
2017-08-23T07:09:18.94
2017-08-23T07:09:19.946
... Do you have an example where |
@vtjnash Perhaps it's just the naming that is causing confusion. I assumed that Perhaps the |
One big difference is |
This proposal adds
wait(io::GenericIOBuffer)
to wait for something to be written to the buffer and modifieseof(io::GenericIOBuffer)
to be false ifio.writeable
is true.The aim is to support an async producer / consumer pattern like this:
@quinnj has a FIFOBuffer class in HTTP.jl that attempts to do something like this, but isn't working 100% yet: JuliaWeb/HTTP.jl#74 .
It seems to me that reading and writing from a buffered pipe is generally useful and a good thing to have in Base.
Note: I haven't tried to compile or run the code in this PR, at this point it's just intended as a sketch of how it might look. If I there is support for a change like this, I'll make sure it works and add tests etc.