[Twisted-Python] help with Deferreds
Sergey Magafurov
smagafurov at naumen.ru
Thu Aug 26 04:49:25 MDT 2010
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20100826/5891151b/attachment.html>
More information about the Twisted-Python
mailing list