9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/message_bus/rack/middleware.rb', line 9
def start_listener
unless @started_listener
thin = defined?(Thin::Server) && ObjectSpace.each_object(Thin::Server).to_a.first
thin_running = thin && thin.running?
@subscription = @bus.subscribe do |msg|
run = proc do
begin
@connection_manager.notify_clients(msg) if @connection_manager
rescue
@bus.logger.warn "Failed to notify clients: #{$!} #{$!.backtrace}"
end
end
if thin_running
EM.next_tick(&run)
else
MessageBus.timer.queue(&run)
end
@started_listener = true
end
end
end
|