0

The setup in Pika's example code with Twisted looks like this:

parameters = pika.ConnectionParameters()
cc = protocol.ClientCreator(
        reactor, twisted_connection.TwistedProtocolConnection, parameters)
d = cc.connectTCP('hostname', 5672)
d.addCallback(lambda protocol: protocol.ready)
d.addCallback(run)
reactor.run()

What effect does the d.addCallback(lambda protocol: protocol.ready) line have? Is reading the .ready attribute side-effecting? Or does addCallback use the return value of the callback?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137

1 Answers1

2

Return value of each callback is passed to next callback in the d's callback chain. So, protocol.ready value is passed to run (next callback).

See http://twistedmatrix.com/documents/current/core/howto/defer.html#multiple-callbacks

monoid
  • 1,661
  • 11
  • 16