You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 15, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 15, 2026. It is now read-only.
Currently io.wait(:read_write) returns nil, false or the io object. Therefore it is not distinguishable if a read or write event was received. But this information is necessary in most cases, where IO#wait_readable or IO#wait_writable aren't suitable. On the C level both the old rb_wait_for_single_fd as well as the new rb_io_wait provide this information, but it is not passed to the Ruby level.
Returning the io object makes not much sense to me. It can not be used to chain calls together, since IO#wait can also return true. And it makes sense for IO.select but not for IO#wait where there's only a single IO object.
IMHO the return value should be changed to return an Integer event mask (out of IO::WRITABLE, IO::READABLE, IO::PRIORITY). The IO#wait method was declared as experimental in 2016. Not sure if this is still true. I doubt that there is any use of the returned IO in the wild.
Alternatively another method or method parameter could be added to enable returning the event mask.
A workaround is to use the scheduler or IO.select like so:
The form io.wait(events, timeout) -> event mask or false. was introduced by me because the original form io.wait(timeout = nil, mode = :read) -> event mask or false. was practically useless and didn't match the C interface which already existed. To be honest, I don't think I changed the original one much, but you are right there is confusion over the interface of these methods. The C implementation returns the event mask. It's been a while since I checked io/wait implementation, but the interface introduced by me should be correct, and the old one might be different depending on the version, but in all cases it should be falsy if the wait failed and truthy if the wait succeeded, which is why I return event mask | false (rather than just event mask | 0) to try and have some level of compatibility. However, I'd have to check the actual implementation.
Activity
eregon commentedon Mar 29, 2022
That seems a bug, because the documentation says:
So it should always return an event mask or false according to the docs, and indeed that would be more useful.
cc @ioquatix
ioquatix commentedon Mar 29, 2022
The form
io.wait(events, timeout) -> event mask or false.was introduced by me because the original formio.wait(timeout = nil, mode = :read) -> event mask or false.was practically useless and didn't match the C interface which already existed. To be honest, I don't think I changed the original one much, but you are right there is confusion over the interface of these methods. The C implementation returns the event mask. It's been a while since I checkedio/waitimplementation, but the interface introduced by me should be correct, and the old one might be different depending on the version, but in all cases it should be falsy if the wait failed and truthy if the wait succeeded, which is why I returnevent mask | false(rather than justevent mask | 0) to try and have some level of compatibility. However, I'd have to check the actual implementation.ioquatix commentedon Jun 25, 2022
This is now fixed by #19
larskanis commentedon Jun 25, 2022
Thank you so much @ioquatix , this is exactly how I thought it should be implemented.