Class: Mongo::Event::Listeners

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/event/listeners.rb

Overview

The queue of events getting processed in the client.

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initializeListeners

Initialize the event listeners.

Examples:

Initialize the event listeners.

Listeners.new

Since:

  • 2.0.0



29
30
31
# File 'lib/mongo/event/listeners.rb', line 29

def initialize
  @listeners = {}
end

Instance Method Details

#add_listener(event, listener) ⇒ Array<Object>

Add an event listener for the provided event.

Examples:

Add an event listener

publisher.add_listener("my_event", listener)

Parameters:

  • event (String)

    The event to listen for.

  • listener (Object)

    The event listener.

Returns:

  • (Array<Object>)

    The listeners for the event.

Since:

  • 2.0.0



44
45
46
# File 'lib/mongo/event/listeners.rb', line 44

def add_listener(event, listener)
  listeners_for(event).push(listener)
end

#listeners_for(event) ⇒ Array<Object>

Get the listeners for a specific event.

Examples:

Get the listeners.

publisher.listeners_for("test")

Parameters:

  • event (String)

    The event name.

Returns:

  • (Array<Object>)

    The listeners.

Since:

  • 2.0.0



58
59
60
# File 'lib/mongo/event/listeners.rb', line 58

def listeners_for(event)
  @listeners[event] ||= []
end