lib/ably/modules/event_emitter.rb in ably-1.2.2 vs lib/ably/modules/event_emitter.rb in ably-1.2.3

- old
+ new

@@ -44,13 +44,16 @@ end end # On receiving an event matching the event_name, call the provided block # + # @spec RTE4 + # # @param [Array<String>] event_names event name # # @return [void] + # def on(*event_names, &block) add_callback event_names, proc_for_block(block) end # Equivalent of {#on} but any exception raised in a block will bubble up and cause this client library to fail. @@ -60,13 +63,16 @@ add_callback event_names, proc_for_block(block, unsafe: true) end # On receiving an event maching the event_name, call the provided block only once and remove the registered callback # + # @spec RTE4 + # # @param [Array<String>] event_names event name # # @return [void] + # def once(*event_names, &block) add_callback event_names, proc_for_block(block, delete_once_run: true) end # Equivalent of {#once} but any exception raised in a block will bubble up and cause this client library to fail. @@ -74,11 +80,15 @@ # @api private def unsafe_once(*event_names, &block) add_callback event_names, proc_for_block(block, delete_once_run: true, unsafe: true) end - # Emit an event with event_name that will in turn call all matching callbacks setup with `on` + # Emits an event, calling registered listeners with the given event name and any other given arguments. + # If an exception is raised in any of the listeners, the exception is caught by the EventEmitter and the exception is logged to the Ably logger. + # + # @spec RTE6 + # def emit(event_name, *args) [callbacks_any, callbacks[callbacks_event_coerced(event_name)]].each do |callback_arr| callback_arr.clone. select do |proc_hash| if proc_hash[:unsafe] @@ -95,12 +105,15 @@ # Remove all callbacks for event_name. # # If a block is provided, only callbacks matching that block signature will be removed. # If block is not provided, all callbacks matching the event_name will be removed. # + # @spec RTE5 + # # @param [Array<String>] event_names event name # # @return [void] + # def off(*event_names, &block) off_internal(false, *event_names, &block) end # Equivalent of {#off} but only unsafe listeners are removed.