Class: Rasti::Web::Channel
- Inherits:
-
Object
- Object
- Rasti::Web::Channel
- Defined in:
- lib/rasti/web/channel.rb
Instance Attribute Summary collapse
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id) ⇒ Channel
constructor
A new instance of Channel.
- #publish(message) ⇒ Object
- #subscribe ⇒ Object
Constructor Details
#initialize(id) ⇒ Channel
7 8 9 10 11 12 |
# File 'lib/rasti/web/channel.rb', line 7 def initialize(id) @mutex = Mutex.new @channel = Restruct::Channel.new id: Restruct::Id[Web.channels_prefix][id] @streams = [] listen end |
Instance Attribute Details
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
5 6 7 |
# File 'lib/rasti/web/channel.rb', line 5 def streams @streams end |
Class Method Details
.[](id) ⇒ Object
26 27 28 29 |
# File 'lib/rasti/web/channel.rb', line 26 def self.[](id) @channels ||= Hash.new { |h,k| h[k] = self.new k } @channels[id] end |
Instance Method Details
#publish(message) ⇒ Object
22 23 24 |
# File 'lib/rasti/web/channel.rb', line 22 def publish() channel.publish end |
#subscribe ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rasti/web/channel.rb', line 14 def subscribe Stream.new.tap do |stream| mutex.synchronize do streams << stream end end end |