summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2023-03-10 16:40:05 +1300
committerGitHub <noreply@github.com>2023-03-10 16:40:05 +1300
commit86d38b452005a9168eb2b5eaffd5fb3465313436 (patch)
tree18a246c3f25a0a35ad4118738345a698252b5d52 /process.c
parentdcc8ecdee8d81963d28d974143cb6f2d7ea489c4 (diff)
downloadruby-86d38b452005a9168eb2b5eaffd5fb3465313436.tar.gz
Accept `sleep(nil)` as sleep forever. (#7484)
Diffstat (limited to 'process.c')
-rw-r--r--process.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/process.c b/process.c
index 2c29af787b..705483bdc4 100644
--- a/process.c
+++ b/process.c
@@ -4918,6 +4918,9 @@ rb_f_spawn(int argc, VALUE *argv, VALUE _)
* thread calls Thread#run. Called without an argument, sleep()
* 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
* sleep 1.2 #=> 1
* 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);
}
else {
- if (argc == 0) {
+ if (argc == 0 || (argc == 1 && NIL_P(argv[0]))) {
rb_thread_sleep_forever();
}
else {