module Emitter
Module Emitter
provides interface to execute events and acknowledgments
@author Maanav Shah <shahmaanav07@gmail.com>
Public Instance Methods
Executes a handler for a particular event
@param [String] key An index to insert handler in events @param [Hash] object Data received from ScServer
# File lib/socketclusterclient/emitter.rb, line 62 def execute(key, object) function = @events[key] if @events.key?(key) function.call(key, object) if function end
Executes a handler and an acknowledgment for a particular event
@param [String] key An index to retrieve handler from events @param [Hash] object Data received from ScServer @param [Lambda] ack A block to execute as acknowledgment
# File lib/socketclusterclient/emitter.rb, line 87 def executeack(key, object, ack) function = @events_ack[key] if @events_ack.key?(key) function.call(key, object, ack) if function end
Checks acknowledgment for an event
@param [String] key An index to retrieve handler from events
# File lib/socketclusterclient/emitter.rb, line 74 def haseventack(key) @events_ack[key] end
Initiarizes events and acks in emitter
# File lib/socketclusterclient/emitter.rb, line 13 def initialize_emitter @events = {} @events_ack = {} end
Adds a handler for a particular event
@param [String] key An index to insert handler in events @param [Lambda] function A block to execute on event
# File lib/socketclusterclient/emitter.rb, line 26 def on(key, function) @events[key] = function end
Adds an acknowledgment handler for a particular event
@param [String] key An index to insert handler in acknowledgment @param [Lambda] function An acknowledgment block to execute on event
# File lib/socketclusterclient/emitter.rb, line 50 def onack(key, function) @events_ack[key] = function end
Adds a handler for a particular channel event
@param [String] key An index to insert handler in events @param [Lambda] function A block to execute on event
# File lib/socketclusterclient/emitter.rb, line 38 def onchannel(key, function) @events[key] = function end