diff options
author | Erik Johnston <erik@matrix.org> | 2019-05-09 13:21:57 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-05-14 11:58:01 +0100 |
commit | b54b03f9e1abc1964fe5f00115a165a2b8e10df5 (patch) | |
tree | bb2a357af902fbdfa935da416a6beaedbd5c8a02 /synapse/util/async_helpers.py | |
parent | Migrate all tests to use the dict-based config format instead of hanging item... (diff) | |
download | synapse-b54b03f9e1abc1964fe5f00115a165a2b8e10df5.tar.xz |
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..9a17dfdab2 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: 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. |