Index: doc/core/howto/listings/TwistedQuotes/pbquote2.py =================================================================== --- doc/core/howto/listings/TwistedQuotes/pbquote2.py (revision 0) +++ doc/core/howto/listings/TwistedQuotes/pbquote2.py (revision 0) @@ -0,0 +1,15 @@ +from random import choice +from twisted.internet import reactor, defer +from twisted.spread import pb + +class DelayedQuoteReader(pb.Root): + + def __init__(self, quoteList): + self.quotes = quoteList + + def remote_nextQuote(self): + d = defer.Deferred() + d.addCallback(choice) + reactor.callLater(2, d.callback, self.quotes) + return d + Index: doc/core/howto/pb-usage.xhtml =================================================================== --- doc/core/howto/pb-usage.xhtml (revision 19962) +++ doc/core/howto/pb-usage.xhtml (working copy) @@ -243,6 +243,25 @@ setting up your own application. Here are some of the other building blocks you can use.
+A remote method may return a Deferred.
This (admittedly silly) DelayedQuoteReader
+implementation returns a deferred instead of a string. When the deferred
+fires the result of its callback will be serialized and sent over the wire to
+the remote caller.
Likewise, many callbacks may be chained together, each one except the last
+returning a Deferred.
+The result of the last callback in the chain will be serialized and sent back
+to the remote caller. This allows remote_ methods
+to perform complex deferred logic.
Here is an example of using