Class: WideReceiver::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/wide_receiver/registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



9
10
11
12
# File 'lib/wide_receiver/registry.rb', line 9

def initialize
  @registry = Hash.new { |h,k| h[k] = [] }
  @lock = Mutex.new
end

Class Method Details

.instanceObject



5
6
7
# File 'lib/wide_receiver/registry.rb', line 5

def self.instance
  @instance ||= new
end

Instance Method Details

#[](channel) ⇒ Object



22
23
24
# File 'lib/wide_receiver/registry.rb', line 22

def [](channel)
  @lock.synchronize { @registry[channel] }
end

#channelsObject



26
27
28
# File 'lib/wide_receiver/registry.rb', line 26

def channels
  @lock.synchronize { @registry.keys }
end

#register(worker_class, channels) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/wide_receiver/registry.rb', line 14

def register(worker_class, channels)
  @lock.synchronize do
    channels.each do |channel|
      @registry[channel] << worker_class
    end
  end
end