Skip to main content

A simple implementation of Observer pattern via Signals

Project description

Green Rocket is a simple implementation of Observer (or Publish/Subscribe)

design pattern using Signals.

Create specific signal from base class:

>>> from greenrocket import Signal
>>> class MySignal(Signal):
...     pass
...

Subscribe handler:

>>> @MySignal.subscribe
... def handler(signal):
...     print('handler: ' + repr(signal))
...

Fire signal:

>>> MySignal().fire()
handler: MySignal()

Note, that signal propagates over inheritance, i.e. all subscribes of base signal will be called when child signal fired:

>>> @Signal.subscribe
... def base_hadler(signal):
...     print('base_handler: ' + repr(signal))
...
>>> MySignal().fire()
handler: MySignal()
base_handler: MySignal()

Unsubscribe handler:

>>> MySignal.unsubscribe(handler)
>>> MySignal().fire()
base_handler: MySignal()

Any keyword argument passed to signal constructor becomes its attribute:

>>> s = Signal(a=1, b=2)
>>> s.a
1
>>> s.b
2

Project details


Release history Release notifications

History Node

0.30

History Node

0.22

History Node

0.21

History Node

0.20

History Node

0.11

This version
History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
GreenRocket-0.1.tar.gz (3.4 kB) Copy SHA256 hash SHA256 Source None Feb 28, 2013

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