Code Monkey home page Code Monkey logo

pyee's Introduction

pyee

image

pyee supplies an EventEmitter object similar to the EventEmitter from Node.js.

Example:

In [1]: from pyee import EventEmitter

In [2]: ee = EventEmitter()

In [3]: @ee.on('event')
   ...: def event_handler():
   ...:     print 'BANG BANG'
   ...:

In [4]: ee.emit('event')
BANG BANG

In [5]:

Easy-peasy.

Installation:

sudo pip install pyee

Methods:

ee.on(event, f=None): Registers the function f to the event name event. Example:

ee.on('data', some_fxn)

If f is not specified, ee.on returns a function that takes f as a callback, which allows for decorator styles:

@ee.on('data')
def data_handler(data):
    print data

ee.emit(event, *args,kwargs)*: Emits the event, calling the attached functions with ``args. For example:: ee.emit('data', '00101001') This will calldata('00101001')'(assumingdatais an attached function). ReturnsFalseif no functions are attached to handle the emission (otherwiseTrue). **ee.once(event, f=None)**: The same asee.on, except that the listener is automatically removed after it's called. **ee.remove_listener(event, fxn)**: Removes the functionfxnfromevent. Requires that the function is not closed over byee.on(using this with the decorator style is unfortunately not possible). **ee.remove_all_listeners(event)**: Removes all listeners fromevent. **ee.listeners(event)**: Returns the array of all listeners registered to the givenevent``.

(Special) Events: -------

"new_listener": Fires whenever a new listener is created. Listeners for this event do not fire upon their own creation.

"error": When emitted raises an Exception by default, behavior can be overriden by attaching callback to the event. For example:

@ee.on('error')
def onError(message):
    logging.err(message)

ee.emit('error', Exception('something blew up'))

Tests:

nosetests

License:

MIT.

pyee's People

Contributors

doboy avatar jfhbrook avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.