class Vissen::Input::Broker::PropagationControl

Internal class used by the `Broker` to control the propagation of a message and provide a control surface for subscription handlers, allowing them to stop the propagation at priorites lower than (not equal to) their own.

Usage

The following example uses a propagation control object to stop propagation at priority 1. Note that `#stop?` must be called for each message before `#stop!` to ensure that the correct priority is set.

ctrl = PropagationControl.new
ctrl.stop? 2 # => false
ctrl.stop? 1 # => false

ctrl.stop!

ctrl.stop? 1 # => false
ctrl.stop? 0 # => true

Public Class Methods

new() click to toggle source
# File lib/vissen/input/broker.rb, line 154
def initialize
  @stop_at_priority = -1
  @current_priority = 0
end

Public Instance Methods

stop!() click to toggle source

Sets the priority stopping threshold.

@return [nil]

# File lib/vissen/input/broker.rb, line 172
def stop!
  @stop_at_priority = @current_priority
  nil
end
stop?(priority) click to toggle source

@param priority [Integer] the priority to check out stopping

condition against.

@return [true, false] whether to stop or not.

# File lib/vissen/input/broker.rb, line 162
def stop?(priority)
  return true if priority < @stop_at_priority

  @current_priority = priority
  false
end