Skip to content

Commit

Permalink
Insure concurrent execution of zero tasks returns immediately.
Browse files Browse the repository at this point in the history
fixes #85

PiperOrigin-RevId: 678658517
Change-Id: If1f6616706b8daece557d302d41ed7e3ff5eb9ba
  • Loading branch information
vezhnick authored and copybara-github committed Sep 25, 2024
1 parent ec51add commit 9389dbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions concordia/utils/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def _as_completed(
Raises:
TimeoutError: If all the results are not generated before the timeout.
"""
if not tasks:
return
if max_workers is None:
max_workers = len(tasks)
with _executor(max_workers=max_workers) as executor_:
Expand Down
6 changes: 5 additions & 1 deletion concordia/utils/concurrency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ def test_run_tasks_in_background(self):
with self.subTest('errors'):
self.assertEqual(
{key: type(error) for key, error in errors.items()},
{'error': ExpectedError, 'wait': TimeoutError}
{'error': ExpectedError, 'wait': TimeoutError},
)

def test_run_tasks_empty(self):
results = concurrency.run_tasks({})
self.assertEmpty(results)

def test_map_parallel(self):
results = concurrency.map_parallel(
return_after, [1, 0.5, 0.1], ['a', 'b', 'c']
Expand Down

0 comments on commit 9389dbe

Please sign in to comment.