The pair of methods #write(read)_nonblock
are need in order to do some proceeds on a code you need in case when data isn't ready to be sent or be received. The ruby
docs say the following on the methods:
If the exception is
Errno::EWOULDBLOCK
orErrno::AGAIN
, it is extended by IO::WaitReadable. So IO::WaitReadable can be used to rescue the exceptions for retrying read_nonblock.
Just trap Errno::EAGAIN
exception.
Note that retry
keyword make the method like usual #write(read)
:
begin
io.write_nonblock
rescue Errno::EAGAIN
retry # or do something else
end