lib/metacosm/simulation.rb in metacosm-0.3.0 vs lib/metacosm/simulation.rb in metacosm-0.3.1

- old
+ new

@@ -1,7 +1,12 @@ module Metacosm class Simulation + # TODO protected? + def redis_connection + Redis.new + end + def fire(command) command_queue.push(command) end def command_queue @@ -55,11 +60,11 @@ @on_event_callback[event_dto] end if !@event_publication_channel.nil? event_dto = event.attrs.merge(listener_module: event.listener_module_name, listener_class_name: event.listener_class_name) - redis = Redis.new + redis = redis_connection redis.publish(@event_publication_channel, Marshal.dump(event_dto)) end if !local_events_disabled? listener = listener_for(event) @@ -82,10 +87,10 @@ end def subscribe_for_commands(channel:) p [ :subscribe_to_command_channel, channel: channel ] @command_subscription_thread = Thread.new do - redis = Redis.new + redis = redis_connection begin redis.subscribe(channel) do |on| on.subscribe do |chan, subscriptions| puts "Subscribed to ##{chan} (#{subscriptions} subscriptions)" end