Skip to content

Commit

Permalink
Add a test for lazy enumerators.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 2, 2024
1 parent b8c90e1 commit a882614
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ def enum(task)
expect(result[1]).to be == 2
expect(result[2]).to be == nil
end

it "can stop lazy enumerator" do
# This test will hang on older Rubies without the bug fix:
skip_unless_minimum_ruby_version("3.3.4")

enumerator = Enumerator.new do |yielder|
yielder.yield 1
sleep
yielder.yield 2
end

Sync do |task|
child_task = task.async do
enumerator.next
enumerator.next
end

child_task.stop

expect(child_task).to be(:stopped?)
end
end
end

0 comments on commit a882614

Please sign in to comment.