Class: WideReceiver::Registry
- Inherits:
-
Object
- Object
- WideReceiver::Registry
- Defined in:
- lib/wide_receiver/registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](channel) ⇒ Object
- #channels ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(worker_class, channels) ⇒ Object
Constructor Details
#initialize ⇒ Registry
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
.instance ⇒ Object
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 |
#channels ⇒ Object
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 |