On 4/15/06, <b class="gmail_sendername">Manlio Perillo</b> &lt;<a href="mailto:manlio_perillo@libero.it">manlio_perillo@libero.it</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
from twisted.internet import defer, reactor<br><br><br>def waitFor(seconds):<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;&quot;&quot;It would be nice to have this in twisted.internet.defer.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks to Matt Goodall.<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;&quot;&quot;<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;d = defer.Deferred()<br>&nbsp;&nbsp;&nbsp;&nbsp;reactor.callLater(seconds, lambda: d.callback(None))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;return defer.waitForDeferred(d)<br><br><br>@defer.deferredGenerator<br>def generator():<br>&nbsp;&nbsp;&nbsp;&nbsp;d = defer.waitForDeferred(
defer.succeed(1))<br>&nbsp;&nbsp;&nbsp;&nbsp;yield d<br><br>&nbsp;&nbsp;&nbsp;&nbsp;d = defer.waitForDeferred(defer.fail(Exception(&quot;error 1&quot;)))<br>&nbsp;&nbsp;&nbsp;&nbsp;yield d<br><br>#&nbsp;&nbsp;&nbsp;&nbsp;raise Exception(&quot;error 2&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;yield waitFor(3)</blockquote><div>
<br>You want to getResult() the result from waitFor().<br><br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&nbsp;&nbsp;&nbsp;&nbsp;d = defer.waitForDeferred
(defer.succeed(2))</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&nbsp;&nbsp;&nbsp;&nbsp;yield d</blockquote><div><br>You want to getResult() the result from waitForDeferred.
<br><br>getResult() is the thing that (either returns a result or) raises any exceptions that a Deferred has failed with, so it's important to always call it.<br></div><br></div><br>-- <br>Christopher Armstrong<br>International Man of Twistery
<br><a href="http://radix.twistedmatrix.com/">http://radix.twistedmatrix.com/</a><br><a href="http://twistedmatrix.com/">http://twistedmatrix.com/</a><br><a href="http://canonical.com/">http://canonical.com/</a><br>