diff options
author | Jean Boussier <[email protected]> | 2022-10-06 15:53:16 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2022-10-17 16:56:00 +0200 |
commit | 60defe0a68a40d1b3225cf6b971ea195e19ae2e2 (patch) | |
tree | 65072a9531c7eb9abfa887a1ad0c18bd4242502d /spec/ruby/shared/queue/deque.rb | |
parent | 7db29de008bbf06ce1dc2a1e9fd9c9684b31e325 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6500
Diffstat (limited to 'spec/ruby/shared/queue/deque.rb')
-rw-r--r-- | spec/ruby/shared/queue/deque.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb index ed32bd29c8..616e56ec8a 100644 --- a/spec/ruby/shared/queue/deque.rb +++ b/spec/ruby/shared/queue/deque.rb @@ -87,6 +87,13 @@ describe :queue_deq, shared: true do t.join end + it "immediately returns nil if no item is available and the timeout is 0" do + q = @object.call + q << 1 + q.send(@method, timeout: 0).should == 1 + q.send(@method, timeout: 0).should == nil + end + it "raise TypeError if timeout is not a valid numeric" do q = @object.call -> { q.send(@method, timeout: "1") }.should raise_error( |