Skip to content

Commit fa6c830

Browse files
committed
More test coverage.
1 parent 5bf223f commit fa6c830

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/async/timeout.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def cancelled?
5858
@handle.cancelled?
5959
end
6060

61+
class CancelledError < RuntimeError
62+
end
63+
6164
# Reschedule the timeout to occur at the specified time.
6265
#
6366
# @parameter time [Numeric] The new time to schedule the timeout for.
@@ -72,7 +75,7 @@ def cancelled?
7275

7376
return time
7477
else
75-
raise RuntimeError, "Cannot reschedule a cancelled timeout!"
78+
raise CancelledError, "Cannot reschedule a cancelled timeout!"
7679
end
7780
end
7881
end

test/async/timeout.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,14 @@
4545
expect(timeout).to be(:cancelled?)
4646
end
4747
end
48+
49+
it "can't reschedule a cancelled timeout" do
50+
scheduler.with_timeout(1) do |timeout|
51+
timeout.cancel!
52+
expect do
53+
timeout.adjust(1)
54+
end.to raise_exception(Async::Timeout::CancelledError)
55+
end
56+
end
4857
end
4958
end

0 commit comments

Comments
 (0)