Twisted deferred chaining
<p>I have an application that manages modules calls asynchronously:</p>

<ul>
<li>it requests a deferred that triggers itself</li>
<li>appends custom callback</li>
<li>checks the returned code to see if = <strong>CONTINUE</strong>, otherwise handle errors</li>
</ul>

<p>This is the code that returns a deferred to the main application:</p>

<pre><code>def xxfi_connect(self, hostname):
    d = defer.Deferred()
    d.callback(Milter.ReturnCodes.CONTINUE)
    return d
</code></pre>

<p>To asynchronously append some code, I need to hook up my function call in the deferred function like this:</p>

<pre><code>d = defer.Deferred()
d.addCallback(self.run_mods, application.L_CONNECT)
d.callback(Milter.ReturnCodes.CONTINUE)
</code></pre>

<p>The trouble is that every function hooked up receive an argument containing the callback parameter (application.L_CONNECT).</p>

<p>Is it possible to achieve this without transporting the returncode in every function call ?</p>

<p>Ideally, I'd like my callback function to be like this:</p>

<pre><code>def run_mods(self, level):
    pass
</code></pre>

<p>instead of </p>

<pre><code>def run_mods(self, code, level):
    pass
</code></pre>

<p>because the <code>code</code> (Milter.ReturnCodes.CONTINUE) is only needed at the end of the chain</p>