The PEAK Developers' Center   Diff for "events" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2005-07-20 16:18:53 and 2005-08-15 12:12:40 (spanning 3 versions)

Deletions are marked like this.
Additions are marked like this.

 
=== Hello World ===
 
To use PEAK's event system it's pretty straught forward. You create an
To use PEAK's event system it's pretty straightforward. You create an
event source, you subscribe to its event and then wait for the event to be
triggered. The event source we are going to use is called ``Broadcaster``,
we'll talk about it more a bit further.
 
{{{#!python
{{{
#!python
from peak.events.api import *
 
source = Broadcaster ()

}}}
 
The ``canceller`` object is a reference to our subscription, once the
reference is lost our subscrition os lost too. We can cancel our
reference is lost our subscription is lost too. We can cancel our
subscription explicitly by calling the ``canceller`` object.
 
The output would be:
{{{
Hello world!
}}}
=== Another Event Source ===
 
Two event sources are called ``Distributer`` and ``Broadcaster``. An event
source it's what you have to subscribe to listen for the events they send.
Two event sources are called ``Distributor`` and ``Broadcaster``. An event
source is what you have to subscribe to listen for the events they send.
 
The difference between ``Distributer`` and a ``Broadcaster`` is a very simple
The difference between ``Distributor`` and a ``Broadcaster`` is a very simple
one. You may assign more then one listener (or callback) to an event source.
When the event source generates a given event it will iterate over it's
listeners, by the order they were subscribed, and send the event to each
one. In the case of a ``Distributer`` when one of its listeners returns
``True`` the iteration stops.
When the event source generates a given event, it will iterate over its
listeners in the order in which they were subscribed and send the event to each
one. In the case of a ``Distributer``, when one of its listeners returns
``True``, the iteration stops.
 
{{{#!python
{{{
#!python
from peak.events.api import *
 
source_dist = Distributer ()
source_dist = Distributor ()
source_bcst = Broadcaster ()
 
def callback1 (source, event):

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck