|
7 | 7 |
|
8 | 8 | Here's a quick tour of the Effect library: |
9 | 9 |
|
10 | | -- Intent: An object which specifies some action to perform, ideally with simple |
11 | | - inert data in public attributes. For example, ReadLine(prompt='> ') |
| 10 | +- Intent: An object which describes a desired action, ideally with simple |
| 11 | + inert data in public attributes. For example, ``ReadLine(prompt='> ')`` could |
| 12 | + be an intent that describes the desire to read a line from the user after |
| 13 | + showing a prompt. |
12 | 14 | - :obj:`Effect`: An object which binds callbacks to receive the result of |
13 | 15 | performing an intent. |
14 | 16 | - Performer: A callable that takes the Dispatcher, an Intent, and a Box. It |
15 | 17 | executes the Intent and puts the result in the Box. For example, the |
16 | | - performer for ReadLine() would read a line from STDIN. |
| 18 | + performer for ``ReadLine()`` could call ``raw_input(intent.prompt)``. |
17 | 19 | - Dispatcher: A callable that takes an Intent and finds the Performer that can |
18 | 20 | execute it (or None). See :obj:`TypeDispatcher` and :obj:`ComposedDispatcher` |
19 | 21 | for handy pre-built dispatchers. |
20 | | -- Box: An object that has 'succeed' and 'fail' methods for providing the result |
21 | | - of an execution (potentially asynchronously). Usually you don't need to care |
22 | | - about this, if you define your performers with :func:`effect.sync_performer` |
23 | | - or :func:`effect.twisted.deferred_performer`. |
| 22 | +- Box: An object that has ``succeed`` and ``fail`` methods for providing the |
| 23 | + result of an execution (potentially asynchronously). Usually you don't need |
| 24 | + to care about this, if you define your performers with |
| 25 | + :func:`effect.sync_performer` or :func:`effect.twisted.deferred_performer`. |
24 | 26 |
|
25 | 27 | There's a few main things you need to do to use Effect. |
26 | 28 |
|
27 | 29 | - Define some intents to describe your side-effects (or use a library |
28 | 30 | containing intents that already exist). For example, an ``HTTPRequest`` |
29 | | - intent that has 'method', 'url', etc attributes. |
| 31 | + intent that has ``method``, ``url``, etc attributes. |
30 | 32 | - Write your application code to create effects like |
31 | 33 | ``Effect(HTTPRequest(...))`` and attach callbacks to them with |
32 | 34 | :func:`Effect.on`. |
33 | 35 | - As close as possible to the top-level of your application, perform your |
34 | 36 | effect(s) with :func:`perform`. |
35 | 37 | - You will need to pass a dispatcher to :func:`perform`. You should create one |
36 | | - by using :class:`effect.dispatcher.ComposedDispatcher` to compose |
37 | | - :obj:`effect.base_dispatcher` (which performers for built-in effects) and a |
38 | | - :class:`effect.dispatcher.TypeDispatcher` with your own performers (e.g. for |
39 | | - ``HTTPRequest``). |
| 38 | + by creating a :class:`TypeDispatcher` with your own performers (e.g. for |
| 39 | + ``HTTPRequest``), and composing it with :obj:`effect.base_dispatcher` (which |
| 40 | + has performers for built-in effects) using :class:`ComposedDispatcher`. |
40 | 41 | """ |
41 | 42 |
|
42 | 43 | from __future__ import absolute_import |
|
49 | 50 | base_dispatcher) |
50 | 51 | from ._dispatcher import ComposedDispatcher, TypeDispatcher |
51 | 52 |
|
| 53 | + |
52 | 54 | __all__ = [ |
53 | 55 | "Effect", "perform", "NoPerformerFoundError", |
54 | 56 | "NotSynchronousError", "sync_perform", "sync_performer", |
|
0 commit comments