Class: Stream

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

Instance Method Summary collapse

Constructor Details

#initialize(&callback) ⇒ Stream

Returns a new instance of Stream.



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

def initialize(&callback)
  @callback = callback
  @closed = false
end

Instance Method Details

#<<(data) ⇒ Object



17
18
19
20
# File 'lib/pubsubstub/stream.rb', line 17

def <<(data)
  @front.call(data.to_s)
  self
end

#closeObject



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

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pubsubstub/stream.rb', line 22

def closed?
  @closed
end

#each(&front) ⇒ Object



11
12
13
14
15
# File 'lib/pubsubstub/stream.rb', line 11

def each(&front)
  @front = front
  @callback.call(self)
  close
end