Class: BBK::App::Dispatcher::MessageStream
- Inherits:
-
Object
- Object
- BBK::App::Dispatcher::MessageStream
- Defined in:
- lib/bbk/app/dispatcher/message_stream.rb
Constant Summary collapse
- CLOSE_VALUE =
:close
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(size: 10) ⇒ MessageStream
constructor
A new instance of MessageStream.
- #push(message) ⇒ Object (also: #<<)
Constructor Details
#initialize(size: 10) ⇒ MessageStream
Returns a new instance of MessageStream.
11 12 13 14 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 11 def initialize(size: 10) @queue = SizedQueue.new(size) @closed = false end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
9 10 11 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 9 def queue @queue end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
9 10 11 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 9 def stream @stream end |
Instance Method Details
#close ⇒ Object
33 34 35 36 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 33 def close @closed = true @queue << CLOSE_VALUE end |
#each ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 21 def each return to_enum unless block_given? return nil if @closed loop do value = @queue.pop break if value == CLOSE_VALUE yield(value) end end |
#push(message) ⇒ Object Also known as: <<
16 17 18 |
# File 'lib/bbk/app/dispatcher/message_stream.rb', line 16 def push() @queue.push() unless @closed end |