[PEAK] Re: peak.events.activity

P.J. Eby pje at telecommunity.com
Thu Mar 5 00:00:15 EST 2009


At 09:41 PM 3/4/2009 -0500, Andrew Svetlov wrote:
>It will be great if you add to Activity.txt example of receiving
>values from subtasks in more clean way.
>
>Something very simple, like
>
>from peak.events import trellis, activity
>
>
>class TaskExample(trellis.Component):
>     trellis.attrs(
>         start = False,
>         stop = False
>     )
>
>     def wait_for_start(self):
>         i = 0
>         while not self.start:
>             yield "waiting to start %i"%i
>             yield activity.Pause
>             i += 1
>
>     def wait_for_stop(self):
>         i = 0
>         while not self.stop:
>             yield "waiting to stop %i"%i
>             yield activity.Pause
>
>
>     @activity.task
>     def demo(self):
>         for i in self.wait_for_start():
>             print i
>             yield i
>         print "starting"
>         for i in self.wait_for_stop():
>             print i
>             yield i
>         print "stopped"

The above should read:

    yield self.wait_for_start()
    yield self.wait_for_stop()

There is no need to loop over the results.


>It's obvious for me now: when I want to get result from subtask I need
>to iterate over and pass all unexpected results to upcoming stream.
>But it was not obvious after documentation reading.
>
>I'm wrong?

Yes.  ;-)  It's even easier than that, you just yield the invocation; 
you don't loop over it.

By the way, please send your emails to the PEAK mailing list in 
future, not to me directly.  The mailing list address is shown as the 
"maintainer" email on my packages for a reason.



More information about the PEAK mailing list