If you don't like that construct, perhaps this one is nicer:
from twisted.internet.defer import maybeDeferred
def getCachedResult(cache, key):
def _readItem(item):
if item.obsolete():
return None
return item.read()
def _gotResult(item):
def _release(ign):
item.release()
return item
d = maybeDeferred(_readItem, item)
d.addBoth(_release)
d.addCallback(renew)
return d
def _ebNotFound(f):
f.trap(NotFound)
return None
return cache.open(key).addCallbacks(_gotResult, _ebNotFound
Thanks, this is what I was looking for
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python