aboutsummaryrefslogtreecommitdiffstats
path: root/ractor.rb
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-03-02 18:27:44 +0900
committerKoichi Sasada <ko1@atdot.net>2023-03-03 00:08:02 +0900
commit5875fce6ce678c444456cc7eed6f28ef000dac24 (patch)
treed18dce5e9da1c5991b154774a579cd0918a7cef5 /ractor.rb
parent5f3c7ac19674b822c72e09e40cfb58fc71ac501e (diff)
downloadruby-5875fce6ce678c444456cc7eed6f28ef000dac24.tar.gz
`Ractor::Selector#empty?`
It returns the waiting set is empty or not. Also add Ractor::Selector's tests.
Diffstat (limited to 'ractor.rb')
-rw-r--r--ractor.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/ractor.rb b/ractor.rb
index 6c57d65f87..5620eeec38 100644
--- a/ractor.rb
+++ b/ractor.rb
@@ -429,6 +429,18 @@ class Ractor
end
# call-seq:
+ # selector.empty?
+ #
+ # Returns true if the number of ractors in the waiting set at the current time is zero.
+ #
+ # Note that even if <tt>#empty?</tt> returns false, the subsequent <tt>#wait</tt>
+ # may raise an exception because other ractors may close the target ractors.
+ #
+ def empty?
+ __builtin_ractor_selector_empty_p
+ end
+
+ # call-seq:
# selector.wait(receive: false, yield_value: yield_value, move: false) -> [ractor or symbol, value]
#
# Waits Ractor events. It is lighter than Ractor.select() for many ractors.