Skip to content

Commit 8001225

Browse files
Avoid exceptions when waking events.
Assisted-By: devx/3236e566-7538-432e-a30a-2bdf37265ed4
1 parent 76c2402 commit 8001225

1 file changed

Lines changed: 5 additions & 18 deletions

File tree

lib/async/container/events.rb

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,21 @@ def initialize
2525
def <<(event)
2626
@queue << event
2727

28-
begin
29-
@output.write_nonblock(".")
30-
rescue ::IO::WaitWritable
31-
# The pipe is already full, so any select waiter is already awake:
32-
end
28+
# If the pipe is full, any select waiter is already awake:
29+
@output.write_nonblock(".", exception: false)
3330

3431
return self
3532
end
3633

3734
# Remove and return the next queued event.
38-
# @parameter non_block [Boolean] Whether to raise if no event is ready.
39-
# @parameter timeout [Numeric | Nil] The maximum time to wait for an event.
40-
def pop(non_block = false, timeout: nil)
41-
if timeout
42-
event = @queue.pop(non_block, timeout: timeout)
43-
else
44-
event = @queue.pop(non_block)
45-
end
35+
def pop(...)
36+
event = @queue.pop(...)
4637

4738
return unless event
4839

49-
@input.read_nonblock(1)
40+
@input.read_nonblock(1, exception: false)
5041

5142
return event
52-
rescue ::IO::WaitReadable
53-
return event if event
54-
55-
raise
5643
end
5744
end
5845
end

0 commit comments

Comments
 (0)