Class: Rasti::Web::Stream
- Inherits:
-
Object
- Object
- Rasti::Web::Stream
- Defined in:
- lib/rasti/web/stream.rb
Constant Summary collapse
- TIMEOUT =
0.0001
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #each ⇒ Object
-
#initialize ⇒ Stream
constructor
A new instance of Stream.
- #opened? ⇒ Boolean
- #write(message) ⇒ Object
Constructor Details
#initialize ⇒ Stream
Returns a new instance of Stream.
7 8 9 10 |
# File 'lib/rasti/web/stream.rb', line 7 def initialize @queue = Queue.new @closed = false end |
Instance Method Details
#close ⇒ Object
25 26 27 |
# File 'lib/rasti/web/stream.rb', line 25 def close @closed = true end |
#closed? ⇒ Boolean
29 30 31 |
# File 'lib/rasti/web/stream.rb', line 29 def closed? @closed end |
#each ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rasti/web/stream.rb', line 17 def each while opened? = @queue.pop yield if sleep TIMEOUT end end |
#opened? ⇒ Boolean
33 34 35 |
# File 'lib/rasti/web/stream.rb', line 33 def opened? !closed? end |
#write(message) ⇒ Object
12 13 14 15 |
# File 'lib/rasti/web/stream.rb', line 12 def write() raise 'Closed stream' if closed? @queue << end |