[Twisted-Python] way of dealing with returning a deferred from a method/function
Jp Calderone
exarkun at intarweb.us
Thu Dec 4 00:21:11 EST 2003
On Wed, Dec 03, 2003 at 09:37:38PM -0500, Itamar Shtull-Trauring wrote:
> On Wed, 03 Dec 2003 20:48:56 -0500
> Jonathan Simms <slyphon at twistedmatrix.com> wrote:
>
> > [snip]
> >
> > def aLongWait(stuff):
> > d = defer.Deferred()
> > def _():
> > result = doSomeStuffHere(stuff)
> > d.callback(result)
> > reactor.callLater(0, _)
> > return d
>
> Why is this any different? all it does is make d get its result slightly
> afterwards. It doesn't change anything fundemantal. It's virtually
> identical to:
>
> def aLongWait(stuff):
> result = doSomeStuffHere(stuff)
> d = defer.Deferred()
> d.callback(result)
> return d
>
which is better expressed as:
def aLongWait(stuff):
return defer.succeed(doSomeStuffHere(stuff))
Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031204/94116f96/attachment.pgp
More information about the Twisted-Python
mailing list