[Twisted-Python] way of dealing with returning a deferred from a method/function
Jonathan Simms
slyphon at twistedmatrix.com
Sat Dec 6 06:23:23 EST 2003
On Thu, 2003-12-04 at 00:21, Jp Calderone wrote:
> 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
DOH!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031206/b9aba44d/attachment.pgp
More information about the Twisted-Python
mailing list