Issue #12013 has been updated by Tiago Cardoso.


@Nobu, I was thinking whether this shouldn't be extended to the #ready? method. This by default checks whether the descriptor has something to read, but I saw that the source code calls the internal C method rb_io_check_readable. Since there is already a method rb_io_check_writable, wouldn't it make sense to make the #ready method receive an argument? (:r/:w/:rw or :read/:write/:readwrite depending of the final API).

I'd open a new issue if I get your approval. 

----------------------------------------
Misc #12013: io/wait: allow to wait on readable and writable
https://bugs.ruby-lang.org/issues/12013#change-56635

* Author: Tiago Cardoso
* Status: Closed
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
If I have a socket and I want to wait for both read and write events, IO.select is my only co-pilot:

~~~ruby
IO.select([mysock],[mysock])
~~~

the beautiful thing about the `#wait_readable` and `#wait_writable` methods is that I can have a friendlier way to compose sockets for other event loops which monkey-patching `IO.select`. One example is celluloid-io, which has its own wrappers around the network sockets classes.

But I think there is a limitation when I want to listen for both reads and writes. See both examples below:

~~~ruby
IO.select([mysock],[mysock], nil, 30)
# as opposed to
require 'io/wait'
mysock.wait_readable(30) && mysock.wait_writable(30)
~~~

in the second example, I can wait potentially 60 seconds, instead of the 30 from the first example.

I'm not sure which API it should be, my main reference is the celluloid io reactor api in this case:

~~~ruby
mysock.wait(:r)
mysock.wait(:w)
mysock.wait(:rw)
~~~

drawback: there is already a wait method, so backwards compatibility would be gone. or would it? Current arity is 0, which means, one could still alias it to `#wait_readable` if no argument is passed.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>