Skip to content

Use Ractor#value instead of take #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions test/ractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def test_non_frozen(data)
dtype = data.fetch(:dtype)
ary = random_array(dtype)
r = Ractor.new(ary) {|x| x }
ary2 = r.take
# Use Ractor#value in Ruby 3.5+, fallback to #take for older versions
ary2 = r.respond_to?(:value) ? r.value : r.take
assert_equal(ary, ary2)
assert_not_same(ary, ary2)
end
Expand All @@ -20,7 +21,8 @@ def test_frozen(data)
r = Ractor.new(ary1) do |ary2|
[ary2, ary2 * 10]
end
ary2, res = r.take
# Use Ractor#value in Ruby 3.5+, fallback to #take for older versions
ary2, res = r.respond_to?(:value) ? r.value : r.take
assert_equal((dtype != Numo::RObject),
ary1.equal?(ary2))
assert_equal(ary1*10, res)
Expand All @@ -35,7 +37,10 @@ def test_parallel(data)
r2 = Ractor.new(ary1) do |ary4|
ary4 * 10
end
assert_equal(r1.take, r2.take)
# Use Ractor#value in Ruby 3.5+, fallback to #take for older versions
result1 = r1.respond_to?(:value) ? r1.value : r1.take
result2 = r2.respond_to?(:value) ? r2.value : r2.take
assert_equal(result1, result2)
end

def random_array(dtype, n=1000)
Expand Down
Loading