Files
redux-scraper/spec/lib/fork_future_spec.rb
2025-01-01 03:29:53 +00:00

31 lines
740 B
Ruby

# typed: false
require "rails_helper"
describe ForkFuture do
it "join_works" do
captured = "foo"
future1 = ForkFuture.new { captured + "bar" }
future2 = ForkFuture.new { captured + "baz" }
assert_equal "foobar", future1.join
assert_equal "foobaz", future2.join
assert 0.0 < future1.duration
assert 0.0 < future2.duration
end
it "pmap_works" do
captured = 2
mapped = ForkFuture.parallel_map(2, 1..10) { |i| captured * i }
assert_equal (1..10).map { |i| i * 2 }, mapped
end
it "nested_works" do
captured = 2
mapped =
ForkFuture.parallel_map(2, 1..10) do |i|
ForkFuture.new { captured * i }.join
end
assert_equal (1..10).map { |i| i * 2 }, mapped
end
end