Sha256: 4073ad53b7843c7cfe7353bccd496570bf07824158de24a6efa4fbcc4c39f378

Contents?: true

Size: 1.04 KB

Versions: 39

Compression:

Stored size: 1.04 KB

Contents

require "wisper"

# The Wisper implementation of temporary listeners clears all listeners at the end of the block,
# rather the just the ones that were supplied in block. This implementation just clears the specified ones,
# allowing multiple temporary overlapping listeners.

module PactBroker
  module Events
    class TemporaryListeners < Wisper::TemporaryListeners
      def subscribe(*listeners)
        options = listeners.last.is_a?(Hash) ? listeners.pop : {}
        begin
          listeners.each { |listener| registrations << Wisper::ObjectRegistration.new(listener, options) }
          yield
        ensure
          unsubscribe(listeners)
        end
        self
      end

      def unsubscribe(listeners)
        registrations.delete_if do |registration|
          listeners.include?(registration.listener)
        end
      end
    end
  end
end

module PactBroker
  module Events
    extend self

    def subscribe(*args)
      result = nil
      TemporaryListeners.subscribe(*args) do
        result = yield
      end
      result
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
pact_broker-2.107.1 lib/pact_broker/events/subscriber.rb
pact_broker-2.107.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/events/subscriber.rb
pact_broker-2.106.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.105.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.104.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.103.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.102.2 lib/pact_broker/events/subscriber.rb
pact_broker-2.102.1 lib/pact_broker/events/subscriber.rb
pact_broker-2.102.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.101.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.100.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.99.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.98.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.97.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.96.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.95.1 lib/pact_broker/events/subscriber.rb
pact_broker-2.95.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.94.0 lib/pact_broker/events/subscriber.rb
pact_broker-2.93.4 lib/pact_broker/events/subscriber.rb