Permalink
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (30 sloc) 1.77 KB

Events

thor.events.EventEmitter

An event emitter, in the style of Node.JS.

void thor.events.EventEmitter.on ( str event, func listener )

Add the callable listenter to the list of listeners that will be called when event is emitted.

void thor.events.EventEmitter.once ( str event, func listener )

Call listener exactly once, the next time that event is emitted.

void thor.events.EventEmitter.removeListener ( str event, func listener )

Remove the callable listener from the list of those that will be called when event is emitted.

void thor.events.EventEmitter.removeListeners ( str event+ )

Remove all listeners for event. Additional _event_s can be passed as following arguments.

list thor.events.EventEmitter.listeners ( str event )

Return the list of callables listening for event.

void thor.events.EventEmitter.emit ( str event, arg* )

Emit event with zero or more _arg_s.

void thor.events.EventEmitter.sink ( object sink )

Given an object sink, call its method (if present) that corresponds to an events name if and only if there are no listeners for that event.

Decorator thor.events.on ( EventEmitter EventEmitter, str event )

A decorator to nominate functions as event listeners. Its first argument is the EventEmitter to attach to, and the second argument is the event to listen for.

For example:

@on(my_event_emitter, 'blow_up')
def push_red_button(thing):
    thing.red_button.push()

If the event is omitted, the name of the function is used to determine the event. For example, this is equivalent to the code above:

@on(my_event_emitter)
def blow_up(thing):
    thing.red_button.push()