[Twisted-Python] help with Deferreds
terry at jon.es
Thu Aug 26 06:17:41 EDT 2010
> How to rewrite this regular function with Deferred-style?
Something like the below (untested) will do the job. You'd have to make
sure that cache.open returned a deferred that fails with NotFound in case
things don't work out.
It would be simpler to translate your code using inlineCallbacks, but it
might be to your advantage to first see how to do it without that. If you
do take that approach you might want to do some timing tests.
def getCachedResult(cache, key):
def release(result, item):
d = item.read()
d = cache.open(key)
More information about the Twisted-Python