FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
effect/effect/parallel_async.py at master · python-effect/effect · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python-effect
/
effect
Public
Notifications
You must be signed in to change notification settings
Fork
15
Star
386
Code
Issues
10
Pull requests
1
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
effect
/
effect
/
parallel_async.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (29 loc) · 1.05 KB
Breadcrumbs
effect
/
effect
/
parallel_async.py
Copy path
File metadata and controls
37 lines (29 loc) · 1.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Generic asynchronous performers."""
from
functools
import
partial
from
itertools
import
count
from
.
_base
import
perform
from
.
_intents
import
FirstError
def
perform_parallel_async
(
dispatcher
,
intent
,
box
):
"""
A performer for :obj:`ParallelEffects` which works if all child Effects are
already asynchronous. Use this for things like Twisted, asyncio, etc.
WARNING: If this is used when child Effects have blocking performers, it
will run them in serial, not parallel.
"""
effects
=
list
(
intent
.
effects
)
if
not
effects
:
box
.
succeed
([])
return
num_results
=
count
()
results
=
[
None
]
*
len
(
effects
)
def
succeed
(
index
,
result
):
results
[
index
]
=
result
if
next
(
num_results
)
+
1
==
len
(
effects
):
box
.
succeed
(
results
)
def
fail
(
index
,
result
):
box
.
fail
(
FirstError
(
exception
=
result
,
index
=
index
))
for
index
,
effect
in
enumerate
(
effects
):
perform
(
dispatcher
,
effect
.
on
(
success
=
partial
(
succeed
,
index
),
error
=
partial
(
fail
,
index
)),
)
Back
|
FazBrowse Home
|
New Git URL