Le 2014-04-25 01:45, Clayton Daley a écrit :
I imagine rewriting this to the following:

    @classmethod
    @inlineCallbacks
    def from_id(cls, id):
        doc = yield db.get_document(id) # blocking/async db call

        self = cls._new_document(doc) # always synchronous
         yield self.__init__() # blocking/async call
        returnValue(self)

places. I've read that the @inlineCallback code is complicated so I
figured I'd run the idea by the experts before diving down that rabbit
hole.

I am no expert, but the code for inlineCallbacks looks pretty
straightforward, except some special cases handled down the way.

Does anyone see any obvious pitfall? I'm happy to do the legwork
to try and build it, but I'd also welcome any pointers from your (no
doubt extensive) experience writing the twisted version.

I would mostly argue about a semantic problem. inlineCallbacks help
asynchronous code *look* like synchronous code thanks to the sequential
writing. It is however essentially asynchronous and does return a
Deferred.

I do not see any immediate technical pitfall here. I would however be
very careful and double think my design if I were to use Deferred
objects as part of a blocking process.

kaiyou.

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to