> I would probably write it something like this:
>
> def getCachedResult(cache, key):
>      def _gotResult(item):
>          try:
>              if item.obsolete():
>                  return None
>              d = item.read()
>              d.addCallback(lambda data: renew(data))
>          except:
>              item.release()
>              raise
>          d.addBoth(lambda ign: item.release())
>          return d
>
>      def _ebNotFound(f):
>          f.trap(NotFound)
>          return None
>
>      return cache.open(key).addCallbacks(_gotResult, _ebNotFound)
>
> Note: code is untested
>    
My variant is like yours.
I ask this question because I am confusing with this ugly slice of code:

try:
     ...
except:
     item.release()
     raise

Only inlineCallbacks helps me...
Thanks.


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

Reply via email to