Hi Stephan,<div><br><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
from what I understand @defer.inlineCallbacks is used to defer a<br>
async callback function like how i'm using CallLater below, but where<br>
is the yield supposed to be? and how should the below code change?<br><br></blockquote><div><br></div><div>The advantage defer.inlineCallbacks offers is allowing one to wait on the result of a deferred inline, without having nested blocks and closures.</div>
<div><br></div><div>So a generic example could be:</div><div><br></div><div>Without inlinecallbacks:</div><div><br></div><div>def my_func():</div><div> d = func_returnning_deferred()</div><div> def handle_result(r):</div>
<div> # do something with r</div><div> ..</div><div> d.addCallback(handle_result)</div><div> return d</div><div><br></div><div>With inlineCallbacks:</div><div><br></div><div>@defer.inlineCallbacks</div>
<div>def my_func():</div><div> r = yield func_returning_deferred()</div><div> # do stuff with r</div><div><br></div><div>You can see that we don't have to have a nested block with an addCallback. Here the yield returns the result that we'd get in our callback function (an likewise if the errBack fired we've have to wrap that line in a try/except to handle it).</div>
<div><br></div><div>Keep in mind however that @defer.inlineCallbacks can only wrap generators (functions with a yield statement in it)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
def connectionMade(self):<br>
logging.debug("connection made timeout = %d", self.timeout)<br>
@defer.inlineCallbacks<br>
def onTimer():<br>
logging.debug("timeout triggered")<br>
self.firefoxProcess.handleProcessTimedOut()<br>
self.killProcessIfAlive()<br>
d = reactor.callLater(self.timeout, onTimer)</blockquote><div> </div><div>You can see here that onTimer is not a generator (there's no yield) so defer.inlineCallbacks cannot be applied to it. Also, based on what you're doing you don't need it (i.e. you can just remove it).</div>
<div><br></div><div>Keep in mind that callLater doesn't return a deferred - it just schedules onTimer to be called at a later time, which makes sense for what you are doing. If for some reason you want a deferred, I'd take a look at twisted.internet.task.deferLater.</div>
<div><br></div><div>Hope that helps,</div><div>Reza</div><div><br></div></div>-- <br>Reza Lotun<br>mobile: +44 (0)7521 310 763<br>email: <a href="mailto:rlotun@gmail.com" target="_blank">rlotun@gmail.com</a><br>work: <a href="mailto:rlotun@twitter.com" target="_blank">rlotun@twitter.com</a><br>
@rlotun<br><br>
</div></div>