Skip to content

Commit

Permalink
Fix results didn't have same order as futures
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmbmb committed Dec 20, 2023
1 parent 7eb1fd2 commit 838b7f3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/distilabel/utils/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ def when_all_complete(futures: List[Future[T]]) -> Future[T]:
completed, and it will contain the results of the `futures`.
"""
all_done_future = Future()
results = []
results = [None] * len(futures)

def check_all_done(future: Future) -> None:
results.extend(future.result())
# This is done to preserve the order of the results with respect to the order
# of the futures.
index = futures.index(future)
results[index] = future.result()[0]

_, not_done = wait(futures, return_when="FIRST_COMPLETED")
if len(not_done) == 0:
all_done_future.set_result(results)
Expand Down

0 comments on commit 838b7f3

Please sign in to comment.