Accept sleep(nil)
as sleep forever. (#7484)
This commit is contained in:
parent
dcc8ecdee8
commit
86d38b4520
Notes:
git
2023-03-10 03:40:25 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
@ -4918,6 +4918,9 @@ rb_f_spawn(int argc, VALUE *argv, VALUE _)
|
|||||||
* thread calls Thread#run. Called without an argument, sleep()
|
* thread calls Thread#run. Called without an argument, sleep()
|
||||||
* will sleep forever.
|
* will sleep forever.
|
||||||
*
|
*
|
||||||
|
* If the +duration+ is not supplied, or is +nil+, the thread sleeps forever.
|
||||||
|
* Threads in this state may still be interrupted by other threads.
|
||||||
|
*
|
||||||
* Time.new #=> 2008-03-08 19:56:19 +0900
|
* Time.new #=> 2008-03-08 19:56:19 +0900
|
||||||
* sleep 1.2 #=> 1
|
* sleep 1.2 #=> 1
|
||||||
* Time.new #=> 2008-03-08 19:56:20 +0900
|
* Time.new #=> 2008-03-08 19:56:20 +0900
|
||||||
@ -4935,7 +4938,7 @@ rb_f_sleep(int argc, VALUE *argv, VALUE _)
|
|||||||
rb_fiber_scheduler_kernel_sleepv(scheduler, argc, argv);
|
rb_fiber_scheduler_kernel_sleepv(scheduler, argc, argv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (argc == 0) {
|
if (argc == 0 || (argc == 1 && NIL_P(argv[0]))) {
|
||||||
rb_thread_sleep_forever();
|
rb_thread_sleep_forever();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -33,10 +33,6 @@ describe "Kernel#sleep" do
|
|||||||
-> { sleep(-1) }.should raise_error(ArgumentError)
|
-> { sleep(-1) }.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises a TypeError when passed nil" do
|
|
||||||
-> { sleep(nil) }.should raise_error(TypeError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "raises a TypeError when passed a String" do
|
it "raises a TypeError when passed a String" do
|
||||||
-> { sleep('2') }.should raise_error(TypeError)
|
-> { sleep('2') }.should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
@ -55,6 +51,29 @@ describe "Kernel#sleep" do
|
|||||||
t.wakeup
|
t.wakeup
|
||||||
t.value.should == 5
|
t.value.should == 5
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ruby_version_is ""..."3.3" do
|
||||||
|
it "raises a TypeError when passed nil" do
|
||||||
|
-> { sleep(nil) }.should raise_error(TypeError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby_version_is "3.3" do
|
||||||
|
it "accepts a nil duration" do
|
||||||
|
running = false
|
||||||
|
t = Thread.new do
|
||||||
|
running = true
|
||||||
|
sleep(nil)
|
||||||
|
5
|
||||||
|
end
|
||||||
|
|
||||||
|
Thread.pass until running
|
||||||
|
Thread.pass while t.status and t.status != "sleep"
|
||||||
|
|
||||||
|
t.wakeup
|
||||||
|
t.value.should == 5
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Kernel.sleep" do
|
describe "Kernel.sleep" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user