lib/rrj/janus/processus/event.rb in ruby_rabbitmq_janus-2.1.1 vs lib/rrj/janus/processus/event.rb in ruby_rabbitmq_janus-2.2.0.pre.42

- old
+ new

@@ -3,21 +3,22 @@ module RubyRabbitmqJanus module Janus module Concurrencies # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv> - # # Listen standar queue + # # Listen public queue to all Janus instance # # Listen standard queue and sending a block code to thread listen. # The default queue is configured in config file. # # @see file:/config/default.md For more information to config file used. class Event < Concurrency include Singleton - def initalize + def initialize super + @thread = Thread.new { initialize_thread } rescue raise Errors::Janus::Event::Initializer end # Create a thread for execute a block code in a thread @@ -26,22 +27,24 @@ # standard 'from-janus' receive a message.This block is sending to # publisher created for this thread. # # @return [Thread] It's a thread who listen queue and execute action def run(&block) - thread.join + @thread.join Thread.new do - loop { thread.thread_variable_get(:publish).listen_events(&block) } + loop do + @thread.thread_variable_get(:publish).listen_events(&block) + end end rescue raise Errors::Janus::Event::Run end private def transaction_running publisher = Rabbit::Publisher::Listener.new(rabbit) - Thread.current.thread_variable_set(:publish, publisher) + @thread.thread_variable_set(:publish, publisher) end end end end end