Thomas P Jakobsen
2009-06-11 12:15:47 UTC
# HG changeset patch
# User Thomas P Jakobsen <***@cs.au.dk>
# Date 1244721950 -7200
# Node ID e1270881794e39f81445820c4133fad317af6e0f
# Parent 8ec45943c12ab91430d03a8895aabc6f64fe7a37
Clone errors.
diff -r 8ec45943c12a -r e1270881794e viff/util.py
--- a/viff/util.py Wed May 27 22:29:31 2009 +0200
+++ b/viff/util.py Thu Jun 11 14:05:50 2009 +0200
@@ -185,12 +185,16 @@
print fmt % tuple(args)
-def clone_deferred(original):
+def clone_deferred(original, splitErr=True):
"""Clone a Deferred.
The returned clone will fire with the same result as the original
:class:`Deferred`, but will otherwise be independent.
+ If *splitErr* is true errors will propagate to both the original
+ and the cloned deferred. If *splitErr* is false errors only
+ propagate into the cloned deferred.
+
It is an error to call :meth:`callback` on the clone as it will
result in an :exc:`AlreadyCalledError` when the original
:class:`Deferred` is triggered.
@@ -212,8 +216,12 @@
def split_result(result):
clone.callback(result)
return result
+ def split_err(error):
+ if splitErr:
+ clone.errback(error)
+ return result
clone = Deferred()
- original.addCallback(split_result)
+ original.addCallbacks(split_result, split_err)
return clone
# User Thomas P Jakobsen <***@cs.au.dk>
# Date 1244721950 -7200
# Node ID e1270881794e39f81445820c4133fad317af6e0f
# Parent 8ec45943c12ab91430d03a8895aabc6f64fe7a37
Clone errors.
diff -r 8ec45943c12a -r e1270881794e viff/util.py
--- a/viff/util.py Wed May 27 22:29:31 2009 +0200
+++ b/viff/util.py Thu Jun 11 14:05:50 2009 +0200
@@ -185,12 +185,16 @@
print fmt % tuple(args)
-def clone_deferred(original):
+def clone_deferred(original, splitErr=True):
"""Clone a Deferred.
The returned clone will fire with the same result as the original
:class:`Deferred`, but will otherwise be independent.
+ If *splitErr* is true errors will propagate to both the original
+ and the cloned deferred. If *splitErr* is false errors only
+ propagate into the cloned deferred.
+
It is an error to call :meth:`callback` on the clone as it will
result in an :exc:`AlreadyCalledError` when the original
:class:`Deferred` is triggered.
@@ -212,8 +216,12 @@
def split_result(result):
clone.callback(result)
return result
+ def split_err(error):
+ if splitErr:
+ clone.errback(error)
+ return result
clone = Deferred()
- original.addCallback(split_result)
+ original.addCallbacks(split_result, split_err)
return clone