Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#wait

(::Integer events, ?::Time::_Timeout timeout) -> (::Integer | false | nil)
(?::Time::_Timeout? timeout, *::IO::wait_mode mode) -> (self | true | false)
io.wait(events, timeout) → event mask, false or nil
io.wait(*event_symbols[, timeout]) → self, true, or false

Waits until the IO becomes ready for the specified events and returns the subset of events that become ready, or a falsy value when times out.

The events can be a bit mask of IO::READABLE, IO::WRITABLE or IO::PRIORITY.

Returns an event mask (truthy value) immediately when buffered data is available.

The second form: if one or more event symbols (:read, :write, or :read_write) are passed, the event mask is the bit OR of the bitmask corresponding to those symbols. In this form, timeout is optional, the order of the arguments is arbitrary, and returns io if any of the events is ready.

See also #ungetc #wait_priority #ungetbyte #wait_readable also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0