Skip to content

Commit 0599f6d

Browse files
committed
Revise IO#wait arguments
1 parent 2ca2cff commit 0599f6d

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

ext/io/wait/wait.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ wait_mode_sym(VALUE mode)
211211
/*
212212
* call-seq:
213213
* io.wait(events, timeout) -> event mask or false.
214-
* io.wait(timeout = nil, mode = :read) -> event mask or false (deprecated)
214+
* io.wait(timeout = nil, mode = :read) -> event mask or false.
215215
*
216216
* Waits until the IO becomes ready for the specified events and returns the
217217
* subset of events that become ready, or +false+ when times out.
@@ -222,34 +222,31 @@ wait_mode_sym(VALUE mode)
222222
* Returns +true+ immediately when buffered data is available.
223223
*
224224
* Optional parameter +mode+ is one of +:read+, +:write+, or
225-
* +:read_write+ (deprecated).
225+
* +:read_write+.
226226
*/
227227

228228
static VALUE
229229
io_wait(int argc, VALUE *argv, VALUE io)
230230
{
231-
VALUE timeout = Qnil;
231+
VALUE timeout = Qundef;
232232
rb_io_event_t events = 0;
233233

234-
if (argc < 2 || (argc >= 2 && RB_SYMBOL_P(argv[1]))) {
235-
if (argc > 0) {
236-
timeout = argv[0];
237-
}
238-
239-
for (int i = 1; i < argc; i += 1) {
240-
events |= wait_mode_sym(argv[i]);
234+
if (argc != 2 || (RB_SYRB_SYMBOL_P(argv[0]) || RB_SYMBOL_P(argv[1]))) {
235+
for (int i = 0; i < argc; i += 1) {
236+
if (RB_SYMBOL_P(argv[i])) {
237+
events |= wait_mode_sym(argv[i]);
238+
}
239+
else if (timeout == Qundef) {
240+
rb_time_interval(timeout = argv[i]);
241+
}
242+
else {
243+
rb_raise(rb_eArgError, "timeout given more than once");
244+
}
241245
}
242246
}
243-
else if (argc == 2) {
247+
else /* argc == 2 */ {
244248
events = RB_NUM2UINT(argv[0]);
245-
246-
if (argv[1] != Qnil) {
247-
timeout = argv[1];
248-
}
249-
}
250-
else {
251-
// TODO error
252-
return Qnil;
249+
timeout = argv[1];
253250
}
254251

255252
if (events == 0) {

0 commit comments

Comments
 (0)