Skip to content

Commit 3789e09

Browse files
samuel-williams-shopifyioquatix
authored andcommitted
Add test for 3.5+.
1 parent a1d1004 commit 3789e09

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

test/async/task.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@
553553
end.wait
554554
end
555555

556-
it "can stop a task and provide a cause" do
556+
it "can stop a task from within with a cause" do
557557
error = nil
558558

559559
cause = Async::Stop::Cause.for("boom")
@@ -572,6 +572,30 @@
572572
expect(error).to be_a(Async::Stop)
573573
expect(error.cause).to be == cause
574574
end
575+
576+
it "can stop a task from outside with a cause" do
577+
skip_unless_minimum_ruby_version("3.5")
578+
579+
error = nil
580+
581+
cause = RuntimeError.new("boom")
582+
583+
task = reactor.async do |task|
584+
begin
585+
task.yield
586+
rescue Async::Stop => error
587+
raise
588+
end
589+
end
590+
591+
task.stop(cause: cause)
592+
593+
reactor.run
594+
595+
expect(task).to be(:stopped?)
596+
expect(error).to be_a(Async::Stop)
597+
expect(error.cause).to be == cause
598+
end
575599
end
576600

577601
with "#sleep" do

0 commit comments

Comments
 (0)