You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/protocol/http/body/streamable.rb
+33-152
Original file line number
Diff line number
Diff line change
@@ -17,85 +17,6 @@ module Body
17
17
#
18
18
# When invoking `call(stream)`, the stream can be read from and written to, and closed. However, the stream is only guaranteed to be open for the duration of the `call(stream)` call. Once the method returns, the stream **should** be closed by the server.
19
19
moduleStreamable
20
-
# Raised when an operation is attempted on a closed stream.
21
-
classClosedError < StandardError
22
-
end
23
-
24
-
# Raised when a streaming body is consumed more than once.
25
-
classConsumedError < StandardError
26
-
end
27
-
28
-
# Single value queue that can be used to communicate between fibers.
29
-
classQueue
30
-
defself.consumer
31
-
self.new(Fiber.current,nil)
32
-
end
33
-
34
-
defself.generator(&block)
35
-
self.new(Fiber.new(&block),Fiber.current)
36
-
end
37
-
38
-
definitialize(generator,consumer)
39
-
@generator=generator
40
-
@consumer=consumer
41
-
@closed=false
42
-
end
43
-
44
-
# The generator fiber can push values into the queue.
45
-
defpush(value)
46
-
raiseClosedError,"Queue is closed!"if@closed
47
-
48
-
ifconsumer=@consumer
49
-
@consumer=nil
50
-
@generator=Fiber.current
51
-
52
-
consumer.transfer(value)
53
-
else
54
-
raiseClosedError,"Queue is not being popped!"
55
-
end
56
-
end
57
-
58
-
# The consumer fiber can pop values from the queue.
raiseConsumedError,"Streaming body has already been consumed!"
203
90
end
204
91
205
-
@output=Output.new(@input,@block)
92
+
@output=Output.schedule(@input,@block)
206
93
@block=nil
207
94
end
208
95
@@ -231,14 +118,12 @@ def call(stream)
231
118
232
119
# Closing a stream indicates we are no longer interested in reading from it.
233
120
defclose(error=nil)
234
-
$stderr.puts"Closing output #{@output}..."
235
121
ifoutput=@output
236
122
@output=nil
237
123
# Closing the output here may take some time, as it may need to finish handling the stream:
238
124
output.close(error)
239
125
end
240
126
241
-
$stderr.puts"Closing input #{@input}..."
242
127
ifinput=@input
243
128
@input=nil
244
129
input.close(error)
@@ -249,29 +134,25 @@ def close(error = nil)
249
134
# A deferred body has an extra `stream` method which can be used to stream data into the body, as the response body won't be available until the request has been sent.
250
135
classDeferredBody < Body
251
136
definitialize(block)
252
-
super(block,Input.new)
137
+
super(block,Writable.new)
253
138
end
254
139
255
-
# Closing a stream indicates we are no longer interested in reading from it.
140
+
# Closing a stream indicates we are no longer interested in reading from it, but in this case that does not mean that the output block is finished generating data.
256
141
defclose(error=nil)
142
+
iferror
143
+
super
144
+
end
257
145
end
258
146
259
147
# Stream the response body into the block's input.
260
148
defstream(body)
261
-
@input.stream(body)
262
-
263
-
$stderr.puts"Closing output #{@output}..."
264
-
ifoutput=@output
265
-
@output=nil
266
-
# Closing the output here may take some time, as it may need to finish handling the stream:
0 commit comments