Class: Rpush::Daemon::DispatcherLoop

Inherits:
Object
  • Object
show all
Includes:
Reflectable
Defined in:
lib/rpush/daemon/dispatcher_loop.rb

Constant Summary collapse

WAKEUP =
:wakeup

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Constructor Details

#initialize(queue, dispatcher) ⇒ DispatcherLoop

Returns a new instance of DispatcherLoop.



8
9
10
11
# File 'lib/rpush/daemon/dispatcher_loop.rb', line 8

def initialize(queue, dispatcher)
  @queue = queue
  @dispatcher = dispatcher
end

Instance Method Details

#startObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/rpush/daemon/dispatcher_loop.rb', line 13

def start
  @thread = Thread.new do
    loop do
      dispatch
      break if @stop
    end

    Rpush::Daemon.store.release_connection
  end
end

#stopObject



24
25
26
# File 'lib/rpush/daemon/dispatcher_loop.rb', line 24

def stop
  @stop = true
end

#waitObject



32
33
34
35
# File 'lib/rpush/daemon/dispatcher_loop.rb', line 32

def wait
  @thread.join if @thread
  @dispatcher.cleanup
end

#wakeupObject



28
29
30
# File 'lib/rpush/daemon/dispatcher_loop.rb', line 28

def wakeup
  @queue.push(WAKEUP) if @thread
end