Class: Rage::Cable::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/cable/adapters/base.rb

Direct Known Subclasses

Redis

Instance Method Summary collapse

Instance Method Details

#pick_a_worker(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rage/cable/adapters/base.rb', line 4

def pick_a_worker(&block)
  _lock, lock_path = Tempfile.new.yield_self { |file| [file, file.path] }

  Iodine.on_state(:on_start) do
    if File.new(lock_path).flock(File::LOCK_EX | File::LOCK_NB)
      if Rage.logger.debug?
        puts "INFO: #{Process.pid} is managing #{self.class.name.split("::").last} subscriptions."
      end
      block.call
    end
  end
end