[ruby-core:112821] [Ruby master Feature#19094] `sleep(nil)` vs `sleep()` and replicating the default implementation.
From:
"ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>
Date:
2023-03-10 03:40:22 UTC
List:
ruby-core #112821
Issue #19094 has been updated by ioquatix (Samuel Williams).
Status changed from Open to Closed
Merged.
----------------------------------------
Feature #19094: `sleep(nil)` vs `sleep()` and replicating the default implementation.
https://bugs.ruby-lang.org/issues/19094#change-102328
* Author: ioquatix (Samuel Williams)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
----------------------------------------
```
> sleep(nil)
(irb):1:in `sleep': can't convert NilClass into time interval (TypeError)
```
However, I feel that this makes implementing a compatible sleep method a little difficult.
```ruby
def sleep(time = nil)
if time
sleep_some(time)
else
sleep_forever
end
end
```
Can we consider allowing `sleep(nil)` and `sleep(false)` to be the same as `sleep()` to simplify this behaviour?
Otherwise, it's hard to proxy (e.g. fiber scheduler, or even just a plain old variable argument).
e.g.
```ruby
class Sleeper
def initialize(time = nil)
@time = time
end
def sleep
Kernel::sleep(@time) # Hard to get the behaviour of `sleep()` here without explicitly handling/checking.
end
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/