Sha256: 1036b0f960b5fdfbf762ad154639bbc966163fe31f61f87366ccf87f8955dc49
Contents?: true
Size: 1.25 KB
Versions: 6
Compression:
Stored size: 1.25 KB
Contents
module Ably::Util # PubSub class provides methods to publish & subscribe to events, with methods and naming # intentionally different to EventEmitter as it is intended for private message handling # within the client library. # # @example # class Channel # def messages # @messages ||= PubSub.new # end # end # # channel = Channel.new # channel.messages.subscribe(:event) { |name| puts "Event message #{name} received" } # channel.messages.publish :event, "Test" # #=> "Event message Test received" # channel.messages.remove :event # class PubSub include Ably::Modules::EventEmitter # Ensure new PubSub object does not share class instance variables def self.new(options = {}) Class.new(PubSub).allocate.tap do |pub_sub_object| pub_sub_object.send(:initialize, options) end end def inspect "<#PubSub: @event_emitter_coerce_proc: #{self.class.event_emitter_coerce_proc.inspect}\n @callbacks: #{callbacks}>" end def initialize(options = {}) self.class.instance_eval do configure_event_emitter options alias_method :subscribe, :on alias_method :publish, :trigger alias_method :unsubscribe, :off end end end end
Version data entries
6 entries across 6 versions & 2 rubygems