Class: RubyAPI::StreamingBody
- Inherits:
-
Object
- Object
- RubyAPI::StreamingBody
- Includes:
- Enumerable
- Defined in:
- lib/rubyapi/streaming.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #each ⇒ Object
-
#initialize ⇒ StreamingBody
constructor
A new instance of StreamingBody.
- #write(data) ⇒ Object
Constructor Details
#initialize ⇒ StreamingBody
Returns a new instance of StreamingBody.
7 8 9 10 |
# File 'lib/rubyapi/streaming.rb', line 7 def initialize @buffer = Queue.new @closed = false end |
Instance Method Details
#close ⇒ Object
16 17 18 19 |
# File 'lib/rubyapi/streaming.rb', line 16 def close @closed = true @buffer << nil end |
#each ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rubyapi/streaming.rb', line 21 def each loop do data = @buffer.pop break if data.nil? yield data end end |
#write(data) ⇒ Object
12 13 14 |
# File 'lib/rubyapi/streaming.rb', line 12 def write(data) @buffer << data.to_s end |