Class: RubyAPI::StreamingBody

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fastrb/streaming.rb

Instance Method Summary collapse

Constructor Details

#initializeStreamingBody

Returns a new instance of StreamingBody.



7
8
9
10
# File 'lib/fastrb/streaming.rb', line 7

def initialize
  @buffer = Queue.new
  @closed = false
end

Instance Method Details

#closeObject



16
17
18
19
# File 'lib/fastrb/streaming.rb', line 16

def close
  @closed = true
  @buffer << nil
end

#closed?Boolean

Returns:



29
30
31
# File 'lib/fastrb/streaming.rb', line 29

def closed?
  @closed
end

#eachObject



21
22
23
24
25
26
27
# File 'lib/fastrb/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/fastrb/streaming.rb', line 12

def write(data)
  @buffer << data.to_s
end