Class: Reel::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/reel/stream.rb

Direct Known Subclasses

ChunkStream, EventStream

Instance Method Summary collapse

Constructor Details

#initialize(&proc) ⇒ Stream

Returns a new instance of Stream.



3
4
5
# File 'lib/reel/stream.rb', line 3

def initialize(&proc)
  @proc = proc
end

Instance Method Details

#call(socket) ⇒ Object



7
8
9
10
# File 'lib/reel/stream.rb', line 7

def call(socket)
  @socket = socket
  @proc.call self
end

#closeObject Also known as: finish



25
26
27
# File 'lib/reel/stream.rb', line 25

def close
  @socket.close unless closed?
end

#closed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/reel/stream.rb', line 30

def closed?
  @socket.closed?
end

#each {|_self| ... } ⇒ Object

behaves like a true Rack::Response/BodyProxy object

Yields:

  • (_self)

Yield Parameters:

  • _self (Reel::Stream)

    the object that the method was called on



21
22
23
# File 'lib/reel/stream.rb', line 21

def each
  yield self
end

#write(data) ⇒ Object Also known as: <<



12
13
14
15
16
17
# File 'lib/reel/stream.rb', line 12

def write(data)
  @socket << data
  data
rescue IOError, Errno::ECONNRESET, Errno::EPIPE
  raise SocketError, "error writing to socket"
end