Make concurrently_execute work with async/await
This commit is contained in:
parent
fec7d88645
commit
09a135b039
|
@ -138,7 +138,7 @@ def concurrently_execute(func, args, limit):
|
||||||
the number of concurrent executions.
|
the number of concurrent executions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
func (func): Function to execute, should return a deferred.
|
func (func): Function to execute, should return a deferred or coroutine.
|
||||||
args (list): List of arguments to pass to func, each invocation of func
|
args (list): List of arguments to pass to func, each invocation of func
|
||||||
gets a signle argument.
|
gets a signle argument.
|
||||||
limit (int): Maximum number of conccurent executions.
|
limit (int): Maximum number of conccurent executions.
|
||||||
|
@ -148,11 +148,10 @@ def concurrently_execute(func, args, limit):
|
||||||
"""
|
"""
|
||||||
it = iter(args)
|
it = iter(args)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def _concurrently_execute_inner():
|
||||||
def _concurrently_execute_inner():
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
yield func(next(it))
|
await maybe_awaitable(func(next(it)))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue