Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
IO::Generic#wait: fix call to Wrapper#wait_any (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
paddor authored Dec 29, 2023
1 parent 23a5167 commit 3238706
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/async/io/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def wait(timeout = self.timeout, mode = :read)
when :write
wait_writable(timeout)
else
wait_any(:rw, timeout)
wait_any(timeout)
end
rescue TimeoutError
return nil
Expand Down
26 changes: 26 additions & 0 deletions spec/async/io/generic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@

[reader, writer].each(&:wait)
end

it "can wait for anything" do
reader = reactor.async do |task|
duration = Async::Clock.measure do
input.wait(1, nil)
end

expect(duration).to be >= wait_duration
expect(input.read(1024)).to be == message

input.close
end

writer = reactor.async do |task|
duration = Async::Clock.measure do
output.wait(1, :write)
end

task.sleep(wait_duration)

output.write(message)
output.close
end

[reader, writer].each(&:wait)
end

it "can return nil when timeout is exceeded" do
reader = reactor.async do |task|
Expand Down

0 comments on commit 3238706

Please sign in to comment.