Class: Rasti::Web::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/web/channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#streamsObject (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(message)
  channel.publish message
end

#subscribeObject



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