summaryrefslogtreecommitdiff
path: root/thread_sync.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-10-06 15:53:16 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-10-17 16:56:00 +0200
commit60defe0a68a40d1b3225cf6b971ea195e19ae2e2 (patch)
tree65072a9531c7eb9abfa887a1ad0c18bd4242502d /thread_sync.rb
parent7db29de008bbf06ce1dc2a1e9fd9c9684b31e325 (diff)
downloadruby-60defe0a68a40d1b3225cf6b971ea195e19ae2e2.tar.gz
thread_sync.c: Clarify and document the behavior of timeout == 0
[Feature #18982] Instead of introducing an `exception: false` argument to have `non_block` return nil rather than raise, we can clearly document that a timeout of 0 immediately returns. The code is refactored a bit to avoid doing a time calculation in such case.
Diffstat (limited to 'thread_sync.rb')
-rw-r--r--thread_sync.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/thread_sync.rb b/thread_sync.rb
index 7e4c341ad0..f8fa69900b 100644
--- a/thread_sync.rb
+++ b/thread_sync.rb
@@ -10,7 +10,7 @@ class Thread
# +ThreadError+ is raised.
#
# If +timeout+ seconds have passed and no data is available +nil+ is
- # returned.
+ # returned. If +timeout+ is +0+ it returns immediately.
def pop(non_block = false, timeout: nil)
if non_block && timeout
raise ArgumentError, "can't set a timeout if non_block is enabled"
@@ -32,7 +32,7 @@ class Thread
# suspended, and +ThreadError+ is raised.
#
# If +timeout+ seconds have passed and no data is available +nil+ is
- # returned.
+ # returned. If +timeout+ is +0+ it returns immediately.
def pop(non_block = false, timeout: nil)
if non_block && timeout
raise ArgumentError, "can't set a timeout if non_block is enabled"
@@ -54,7 +54,7 @@ class Thread
# thread isn't suspended, and +ThreadError+ is raised.
#
# If +timeout+ seconds have passed and no space is available +nil+ is
- # returned.
+ # returned. If +timeout+ is +0+ it returns immediately.
# Otherwise it returns +self+.
def push(object, non_block = false, timeout: nil)
if non_block && timeout