Search code examples
pythoncallbacktwisteddeferred

Twisted - pass result to mutiple callbacks


I have two callback functions B, C and I would like them process the result of function A returning Deferred (A->B->C). Normally, I would join them into one but for a reason, I can't do that.

From what I know, twisted callback pipeline processes return of previous callback. Solution is obviously add B, C as callbacks to A, and pass original return of A to B and through return to C. Is there a better way to do it, something like reverse DeferredList?


Solution

  • Or maybe you could use inlineCallbacks

    `
    from twisted.internet.defer import inlineCallbacks
    
    @inlineCallbacks
    def doThing():
         result = yield A()
         B(result)
         C(result)
    
         # or if it is a function returning a deferred
         yield B(result)
         yield C(result)
    `