Sha256: 523a192ee3d44e6cf5b2acacd9226063ac438b753e84b655e7ddb249e53565c6
Contents?: true
Size: 850 Bytes
Versions: 10
Compression:
Stored size: 850 Bytes
Contents
# Handles temporary global subscriptions # @api private module Wisper class TemporaryListeners def self.subscribe(*listeners, &block) new.subscribe(*listeners, &block) end def self.registrations new.registrations end def subscribe(*listeners, &_block) new_registrations = build_registrations(listeners) begin registrations.merge new_registrations yield ensure registrations.subtract new_registrations end self end def registrations Thread.current[key] ||= Set.new end private def build_registrations(listeners) options = listeners.last.is_a?(Hash) ? listeners.pop : {} listeners.map { |listener| ObjectRegistration.new(listener, options) } end def key '__wisper_temporary_listeners' end end end
Version data entries
10 entries across 10 versions & 3 rubygems