[Twisted-Python] Giving inlineCallbacks-wrapped functions access to the deferred their wrapper will return

glyph at divmod.com glyph at divmod.com
Sat Apr 11 20:40:11 EDT 2009


On 11 Apr, 10:55 pm, terry at jon.es wrote:
>I can get around this in ways that are less elegant:
>
>    @defer.inlineCallbacks
>    def func():
>        # do some stuff
>        d = defer.Deferred()
>        callSomethingElse(d)
>        d.callback(result)
>        newResult = yield d
>        defer.returnValue(newResult)

When I write functions that take a Deferred I typically have them return 
a Deferred as well, to avoid this, and other syntactic nuisances.  Would 
you consider the following more elegant?

    @inlineCallbacks
    def func():
        # do some stuff
        returnValue(yield callSomethingElse(succeed(result)))




More information about the Twisted-Python mailing list