import zope.event
class Blog:
def update(self):
self._update()
zope.event.notify('blogupdate')
This will send a notification to anyone in my application that has a subscription to blogupdate. To subscribe to this topic, we could do something like:
import zope.event
def sub_blogupdate():
log('Blog updated.')
zope.event.subscribers.append(sub_blogupdate)
The subscription would obviously do something more important but this serves well to illustrate the general concept. Publish-subscribe comes in handy when there is a chain of complex events. The zope.event package, although very simplistic, allows us to produce higher quality code.
No comments :
Post a Comment