diff options
author | Erik Johnston <erikj@jki.re> | 2019-05-15 10:36:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-15 10:36:30 +0100 |
commit | 0aba6c82513802822482de6e1e797b07502b92b5 (patch) | |
tree | 5da1073792ad81b5d192dce649b8518cd1907b6b /synapse/util/async_helpers.py | |
parent | Merge pull request #5184 from matrix-org/erikj/expose_get_events_as_array (diff) | |
parent | Update docstring with correct return type (diff) | |
download | synapse-0aba6c82513802822482de6e1e797b07502b92b5.tar.xz |
Merge pull request #5183 from matrix-org/erikj/async_serialize_event
Allow client event serialization to be async
Diffstat (limited to 'synapse/util/async_helpers.py')
-rw-r--r-- | synapse/util/async_helpers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py index 2f16f23d91..7253ba120f 100644 --- a/synapse/util/async_helpers.py +++ b/synapse/util/async_helpers.py @@ -156,6 +156,25 @@ def concurrently_execute(func, args, limit): ], consumeErrors=True)).addErrback(unwrapFirstError) +def yieldable_gather_results(func, iter, *args, **kwargs): + """Executes the function with each argument concurrently. + + Args: + func (func): Function to execute that returns a Deferred + iter (iter): An iterable that yields items that get passed as the first + argument to the function + *args: Arguments to be passed to each call to func + + Returns + Deferred[list]: Resolved when all functions have been invoked, or errors if + one of the function calls fails. + """ + return logcontext.make_deferred_yieldable(defer.gatherResults([ + run_in_background(func, item, *args, **kwargs) + for item in iter + ], consumeErrors=True)).addErrback(unwrapFirstError) + + class Linearizer(object): """Limits concurrent access to resources based on a key. Useful to ensure only a few things happen at a time on a given resource. |