On 08:24 am, michae...@gmail.com wrote:
>2009/5/28 <gl...@divmod.com>

>Thanks for the very interesting example which I mainly follow apart 
>from the
>lineReceived method in the ProxyClient, don't we need to add a callback 
>to
>the deferred before appending it to the requestQueue?

Definitely not!  That would defeat the purpose.  The Deferred doesn't 
have a value yet: you're waiting for the other side of the connection to 
respond with an echo line.  As you can see, the result becomes available 
in lineReceived:
>class ProxyClient(LineReceiver):
>    def connectionMade(self):
>        self.requestQueue = []
>
>    def forwardLine(self, line):
>        self.sendLine(line)
>        d = Deferred()
>        self.requestQueue.append(d)
>        return d

And we callback the Deferred when it is available:
>    def lineReceived(self, line):
>        self.requestQueue.pop(0).callback(line)
>
>Thanks, Michael

HTH,

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to