Skip to content

Commit 1df75c1

Browse files
committed
Better handling of non-yielding multi-return calls.
1 parent 3ce75cb commit 1df75c1

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

lib/async/container/supervisor/connection.rb

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,34 @@ def self.call(connection, **message, &block)
9393
call = self.new(connection, id, message)
9494

9595
connection.calls[id] = call
96-
connection.write(id: id, **message)
97-
98-
if block_given?
99-
call.each(&block)
100-
else
101-
return call.pop
96+
begin
97+
connection.write(id: id, **message)
98+
99+
if block_given?
100+
call.each(&block)
101+
else
102+
intermediate = nil
103+
104+
while response = call.pop
105+
if response.delete(:finished)
106+
if intermediate
107+
if response.any?
108+
intermediate << response
109+
end
110+
111+
return intermediate
112+
else
113+
return response
114+
end
115+
else
116+
# Buffer intermediate responses:
117+
intermediate ||= []
118+
intermediate << response
119+
end
120+
end
121+
end
122+
ensure
123+
connection.calls.delete(id)
102124
end
103125
end
104126
end
@@ -156,7 +178,7 @@ def call(...)
156178

157179
def run(target)
158180
self.each do |message|
159-
if id = message[:id]
181+
if id = message.delete(:id)
160182
if call = @calls[id]
161183
# Response to a call:
162184
call.push(**message)

lib/async/container/supervisor/memory_monitor.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def remove(connection)
4343
end
4444

4545
def status(call)
46-
@processes.each do
47-
call.push(memory_monitor: @cluster)
48-
end
46+
call.push(memory_monitor: @cluster)
4947
end
5048

5149
def run

0 commit comments

Comments
 (0)