lib/vissen/input/broker.rb in vissen-input-0.2.2 vs lib/vissen/input/broker.rb in vissen-input-0.3.0
- old
+ new
@@ -72,13 +72,15 @@
end
# Insert a new message into the message queue. The message is handled at a
# later time in `#run_once`.
#
- # @param message [Message] the message(s) to handle.
+ # @param message [Message, Hash] the message(s) to handle.
def publish(*message)
- message.each { |m| @message_queue.push m }
+ message.each do |m|
+ @message_queue.push m
+ end
end
# Takes one message from the message queue and handles it.
#
# @return [true, false] true if the message_queue contained a message,
@@ -98,20 +100,22 @@
# @return [nil]
def call(message, ctrl)
# TODO: Remap the message if needed.
@subscriptions.each do |subscription|
break if ctrl.stop?(subscription.priority)
- next unless subscription.match? message
- subscription.handle message, ctrl
+ subscription.match message do |msg|
+ subscription.handle msg, ctrl
+ message = msg
+ end
end
nil
end
private
- # Insert of append a new subscription to the list. The subscription will
+ # Insert or append a new subscription to the list. The subscription will
# be placed before the first subscription that is found to have a lower
# priority, or last.
#
# @param subscription [Subscription] the subscription to add.
# @return [Subscription] the subscription that was added.
@@ -150,10 +154,11 @@
def initialize
@stop_at_priority = -1
@current_priority = 0
end
- # @param [Integer] the priority to test if
+ # @param priority [Integer] the priority to check out stopping
+ # condition against.
# @return [true, false] whether to stop or not.
def stop?(priority)
return true if priority < @stop_at_priority
@current_priority = priority