Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 2 additions & 8 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,11 @@ def io_wait(io, events, timeout = nil)

if timeout
timer = @timers.after(timeout) do
fiber.raise(TimeoutError)
fiber.transfer
end
end

# Console.logger.info(self, "-> io_wait", fiber, io, events)
events = @selector.io_wait(fiber, io, events)
# Console.logger.info(self, "<- io_wait", fiber, io, events)

return events
rescue TimeoutError
return false
return @selector.io_wait(fiber, io, events)
ensure
timer&.cancel
end
Expand Down
9 changes: 7 additions & 2 deletions test/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,14 @@ def after
expect(state).to be == :timeout
end

it "will timeout while getting from stdin" do
it "will timeout while getting from input" do
input, output = IO.pipe
error = nil

reactor.async do |task|
begin
task.with_timeout(0.1) {STDIN.gets}
# This can invoke `io_wait`, which previously had `rescue TimeoutError`, causing the timeout to be ignored.
task.with_timeout(0.1) {input.gets}
rescue Async::TimeoutError => error
# Ignore.
end
Expand All @@ -610,6 +612,9 @@ def after
reactor.run

expect(error).to be_a(Async::TimeoutError)
ensure
input.close
output.close
end

it "won't timeout if execution completes in time" do
Expand Down