123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Event::Listeners

Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/event/listeners.rb

Overview

The queue of events getting processed in the client.

Since:

  • 2.0.0

Class Method Summary

Instance Method Summary

Constructor Details

.newListeners

Initialize the event listeners.

Examples:

Initialize the event listeners.

Listeners.new

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/event/listeners.rb', line 32

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

[ GitHub ]

  
# File 'lib/mongo/event/listeners.rb', line 47

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

[ GitHub ]

  
# File 'lib/mongo/event/listeners.rb', line 61

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