Skip to content

Commit d0b949f

Browse files
committed
docstriiiiings
1 parent 183f235 commit d0b949f

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

effect/_base.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,21 @@ def perform(dispatcher, effect):
9999
:obj:`effect.base_dispatcher` for a dispatcher supporting basic intents
100100
like :obj:`Constant` et al.
101101
102-
The performer will often be decorated with :func:`sync_performer` or
103-
something like :func:`.deferred_performer`, and will be
104-
invoked with the dispatcher [#dispatcher]_ and the intent, and should
105-
perform the desired effect. [#box]_
102+
The performer will often be decorated with :func:`sync_performer` or the
103+
``deferred_performer`` from `txeffect`_ and will be invoked with the
104+
dispatcher [#dispatcher]_ and the intent, and should perform the desired
105+
effect. [#box]_ The performer should return the result of the effect, or
106+
raise an exception, and the result will be passed on to the first callback,
107+
then the result of the first callback will be passed to the next callback,
108+
and so on.
109+
110+
.. _`txeffect`: https://warehouse.python.org/project/txeffect
111+
112+
Both performers and callbacks may return regular values, raise exceptions,
113+
or return another Effect, which will be recursively performed, such that
114+
the result of the returned Effect becomes the result passed to the next
115+
callback. In the case of exceptions, the next error-callback will be called
116+
with a ``sys.exc_info()``-style tuple.
106117
107118
Note that this function does _not_ return the final result of the effect.
108119
You may instead want to use :func:`.sync_perform` or

effect/_sync.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class NotSynchronousError(Exception):
1818
def sync_perform(dispatcher, effect):
1919
"""
2020
Perform an effect, and return its ultimate result. If the final result is
21-
an error, the exception will be raised. This is useful for testing, and
22-
also if you're using blocking effect implementations.
21+
an error, the exception will be raised.
2322
2423
This requires that the effect (and all effects returned from any of its
2524
callbacks) be synchronous. If the result is not available immediately,
@@ -42,9 +41,20 @@ def sync_performer(f):
4241
"""
4342
A decorator for performers that return a value synchronously.
4443
45-
The function being decorated is expected to take a dispatcher and an intent
46-
(and not a box), and should return or raise normally. The wrapper function
47-
that this decorator returns will accept a dispatcher, an intent, and a box
44+
This decorator should be used if performing the intent will be synchronous,
45+
i.e., it will block until the result is available and the result will be
46+
simply returned. This is the common case unless you're using an
47+
asynchronous framework like Twisted or asyncio.
48+
49+
Note that in addition to returning (or raising) values as normal, you can
50+
also return another Effect, in which case that Effect will be immediately
51+
performed with the same dispatcher. This is useful if you're implementing
52+
one intent which is built on top of other effects, without having to
53+
explicitly perform them.
54+
55+
The function being decorated is expected to take a dispatcher and an
56+
intent, and should return or raise normally. The wrapper function that this
57+
decorator returns will accept a dispatcher, an intent, and a box
4858
(conforming to the performer interface). The wrapper deals with putting the
4959
return value or exception into the box.
5060

0 commit comments

Comments
 (0)