Project

General

Profile

Misc #12013

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

If I have a socket and I want to wait for both read and write events, IO.select is my only co-pilot:

~~~ruby <pre>
IO.select([mysock],[mysock])
~~~ </pre>

the beautiful thing about the `#wait_readable` #wait_readable and `#wait_writable` #wait_writable methods is that I can have a friendlier way to compose sockets for other event loops which monkey-patching `IO.select`. 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 <pre>
IO.select([mysock],[mysock], nil, 30)
# as opposed to
require 'io/wait'
mysock.wait_readable(30) && mysock.wait_writable(30)
~~~ </pre>

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 <pre>
mysock.wait(:r)

mysock.wait(:w)
mysock.wait(:rw)
~~~ </pre>

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` #wait_readable if no argument is passed.

Back