On Tue, 2005-08-30 at 08:47 +0200, Stefano Masini wrote:
Here is an example that makes justice to this approach. It involves Perspective Broker. Think of writing a web frontend to an application on the backend that exports functionality through pb. (the code may not work, I'm just making it up now without testing it) (I hope everybody is familiar with nevow.stan. If not, take a look at it. It's worth.)
@deferredGreenlet def renderPage(self): dataList = [ blockOn(self.backend.callRemote('getDataFromId', elementId)) for elementId in self.idList] return T.html[ T.body [ 'The result:', T.br, [ (txt, T.br) for txt in dataList ] ] ]
Let me give a counterargument to this specific example - regardless of whether it uses greenlets or just Deferreds: it's slow. Really in this case you'd want callRemote("getDataFromIds", self.idList), or at least to run all the getDataFromId() in parallel, *not* wait for one to finish before calling the other. That being said, I have seen code where something like greenlets or defgen really makes the code much easier to read, so having one of those is worthwhile.