Skip to content

Commit 238a8a2

Browse files
committed
rename effect.async to effect.parallel_async, replace async.py with 'from .parallel_async import *'
this should hopefully allow us to be backwards compatible so older versions of python can still use effect.async, but to switch to python 3.7 you will need to import effect.parallel_async.
1 parent 1a9b252 commit 238a8a2

File tree

6 files changed

+47
-45
lines changed

6 files changed

+47
-45
lines changed

effect/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def perform(dispatcher, effect):
116116
117117
.. [#dispatcher] The dispatcher is passed because some performers need to
118118
make recursive calls to :func:`perform`, because they need to perform
119-
other effects (see :func:`parallel` and :func:`.perform_parallel_async`
120-
for an example of this).
119+
other effects (see :func:`parallel` and
120+
:func:`.parallel_async.perform_parallel_async` for an example of this).
121121
122122
.. [#box] Without using one of those decorators, the performer is actually
123123
passed three arguments, not two: the dispatcher, the intent, and a

effect/_intents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ParallelEffects(object):
2626
An effect intent that asks for a number of effects to be run in parallel,
2727
and for their results to be gathered up into a sequence.
2828
29-
:func:`effect.async.perform_parallel_async` can perform this Intent
29+
:func:`effect.parallel_async.perform_parallel_async` can perform this Intent
3030
assuming all child effects have asynchronous performers.
3131
:func:`effect.threads.perform_parallel_with_pool` can perform blocking
3232
performers in a thread pool.

effect/async.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,2 @@
1-
"""Generic asynchronous performers."""
2-
3-
from functools import partial
4-
from itertools import count
5-
6-
from ._base import perform
7-
from ._intents import FirstError
8-
9-
10-
def perform_parallel_async(dispatcher, intent, box):
11-
"""
12-
A performer for :obj:`ParallelEffects` which works if all child Effects are
13-
already asynchronous. Use this for things like Twisted, asyncio, etc.
14-
15-
WARNING: If this is used when child Effects have blocking performers, it
16-
will run them in serial, not parallel.
17-
"""
18-
effects = list(intent.effects)
19-
if not effects:
20-
box.succeed([])
21-
return
22-
num_results = count()
23-
results = [None] * len(effects)
24-
25-
def succeed(index, result):
26-
results[index] = result
27-
if next(num_results) + 1 == len(effects):
28-
box.succeed(results)
29-
30-
def fail(index, result):
31-
box.fail((FirstError,
32-
FirstError(exc_info=result, index=index),
33-
result[2]))
34-
35-
for index, effect in enumerate(effects):
36-
perform(
37-
dispatcher,
38-
effect.on(
39-
success=partial(succeed, index),
40-
error=partial(fail, index)))
1+
from .parallel_async import *
2+
__all__ = ['perform_parallel_async']

effect/parallel_async.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Generic asynchronous performers."""
2+
3+
from functools import partial
4+
from itertools import count
5+
6+
from ._base import perform
7+
from ._intents import FirstError
8+
9+
10+
def perform_parallel_async(dispatcher, intent, box):
11+
"""
12+
A performer for :obj:`ParallelEffects` which works if all child Effects are
13+
already asynchronous. Use this for things like Twisted, asyncio, etc.
14+
15+
WARNING: If this is used when child Effects have blocking performers, it
16+
will run them in serial, not parallel.
17+
"""
18+
effects = list(intent.effects)
19+
if not effects:
20+
box.succeed([])
21+
return
22+
num_results = count()
23+
results = [None] * len(effects)
24+
25+
def succeed(index, result):
26+
results[index] = result
27+
if next(num_results) + 1 == len(effects):
28+
box.succeed(results)
29+
30+
def fail(index, result):
31+
box.fail((FirstError,
32+
FirstError(exc_info=result, index=index),
33+
result[2]))
34+
35+
for index, effect in enumerate(effects):
36+
perform(
37+
dispatcher,
38+
effect.on(
39+
success=partial(succeed, index),
40+
error=partial(fail, index)))

effect/test_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ._base import Effect, perform
66
from ._dispatcher import ComposedDispatcher, TypeDispatcher
77
from ._intents import ParallelEffects, base_dispatcher, parallel
8-
from .async import perform_parallel_async
8+
from .parallel_async import perform_parallel_async
99
from .test_base import func_dispatcher
1010
from .test_parallel_performers import ParallelPerformerTestsMixin
1111

effect/test_intents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ParallelEffects, parallel_all_errors)
2222
from ._sync import sync_perform
2323
from ._test_utils import MatchesReraisedExcInfo, get_exc_info
24-
from .async import perform_parallel_async
24+
from .parallel_async import perform_parallel_async
2525
from .test_parallel_performers import EquitableException
2626

2727

0 commit comments

Comments
 (0)