Skip to main content

a light-weight event handler

Project description

Teventlet provides a light-weight easy-to-use mechenism for handling events. Each eventlet object is it’s own event, to which you can add callbacks with +=. To call the event, you can call the object with any arguments, or call the invoke method with any arguments.

Purpose

The purpose of Teventlet is to provide a mechenism that can be used to handle events. For example, if you wanted to attach events to an object in a game, for events such as collisions, you would have a teventlet per event. The publisher (in this case whatever checks for collisions) would be responsible for calling the invoke method on the event, while anything wanting to know when a collision occured would add a method to the callback list with the += operator.

Usage

Here is a quick example to get you going.:

>>> from __future__ import print_function
>>> from teventlet import teventlet
>>> adder = teventlet(lambda x:print(x+1), lambda x:print(x+2))
>>> adder.invoke(2)
3
4
>>> len(adder)
2
>>>

As you can see, we pass two lambdas to the adder: a lambda that prints x+1, and a lambda that prints x+2. You could easily replace these with functions. By calling invoke, we pass in an argument that gets sent to our lambdas. You can also call the event as if it were a function.:

>>> adder(5)
6
7
>>>

See Also

I have written a blog post, which can be found at http://tds-solutions.net/blog/?p=137. This gives some more examples of how to use Teventlet, as well as explains it’s purpose in more detail.

Project details


Release history Release notifications

This version
History Node

1.0.1

History Node

1.0

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page