Sha256: 2c817dda154a1a4e4fabdb0d87106b266ea2a8c33d4db64a9ae3f6f3e2c633ac

Contents?: true

Size: 1.09 KB

Versions: 37

Compression:

Stored size: 1.09 KB

Contents

module Ably
  module Modules
    module EventEmitter
      # Unplugs currently registered listener callbacks
      # Ensures multiple calls to unplug is not destructive
      def unplug_listeners
        unplugged_callbacks[:callbacks] = unplugged_callbacks.fetch(:callbacks).merge(callbacks)
        unplugged_callbacks[:callbacks_any] = unplugged_callbacks.fetch(:callbacks_any) + callbacks_any
        callbacks.clear
        callbacks_any.clear
      end

      # Plug in previously unplugged listener callbacks
      # But merge them together in case other listners have been added in the mean time
      def plugin_listeners
        @callbacks = callbacks.merge(unplugged_callbacks.fetch(:callbacks))
        @callbacks_any = callbacks_any + unplugged_callbacks.fetch(:callbacks_any)
        unplugged_callbacks.fetch(:callbacks).clear
        unplugged_callbacks.fetch(:callbacks_any).clear
      end

      private
      def unplugged_callbacks
        @unplugged_callbacks ||= {
          callbacks: Hash.new { |hash, key| hash[key] = [] },
          callbacks_any: []
        }
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
ably-rest-1.2.7 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.7 spec/support/event_emitter_helper.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.6 spec/support/event_emitter_helper.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.4 spec/support/event_emitter_helper.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.3 spec/support/event_emitter_helper.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.2 spec/support/event_emitter_helper.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.1 spec/support/event_emitter_helper.rb
ably-rest-1.2.0 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.2.0 spec/support/event_emitter_helper.rb
ably-rest-1.1.8 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.1.8 spec/support/event_emitter_helper.rb
ably-rest-1.1.7 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.1.7 spec/support/event_emitter_helper.rb
ably-rest-1.1.6 lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb
ably-1.1.6 spec/support/event_emitter_helper.rb