Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

events

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events

  • 0.9.8
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

=Events::Emitter {<img src=https://travis-ci.org/matsadler/rb-event-emitter.png>}[http://travis-ci.org/matsadler/rb-event-emitter]

The Events::Emitter mixin provides a clone of the Node.js EventEmitter API for Ruby.

Instances of classes including Events::Emitter will emit events, events are represented by symbols, underscored in the usual Ruby fashion. Examples: :connection, :data, :message_begin

Blocks can be attached to objects to be executed when an event is emitted, these blocks are called listeners.

All EventEmitters emit the event :new_listener when new listeners are added, this listener is provided with the event and new listener added. Example: server.on(:new_listener) do |event, listener| puts "added new listener #{listener} for event #{event}" end

server.on(:connection) do |socket| puts "someone connected!" end Outputs "added new listener #Proc:0x0000000000000000@example.rb:12 for event connection".

==Events::EventEmitter

The Events::EventEmitter class is provided as a convenience for those who wish to inherit from a class. It simply includes the Events::Emitter module.

==Methods

emitter.on(event, &block)

Adds a listener to the end of the listeners array for the specified event. server.on(:connection) do |socket| puts "someone connected!" end

emitter.once(event, &block)

Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed. server.once(:connection) do |socket| puts "Ah, we have our first user!" end

emitter.remove_listener(event, proc)

Remove a listener from the listener array for the specified event.

emitter.max_listeners = n

By default an EventEmitter will print a warning if more than 10 listeners are added to it. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This method allows that to be increased. Set to zero for unlimited.

emitter.listeners(event)

Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.

emitter.emit(event[, arguments...])

Execute each of the listeners in order with the supplied arguments.

FAQs

Package last updated on 06 May 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc