X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_future.py;h=7dbec5004b4ba927331e71fb812fd482af678c3c;hb=c41e0e59446412511c5737cf5b6ba8f289e75e7e;hp=e4832d43d5b1674988628e5dae43a67cf8ed0565;hpb=3bc4daf1edc121cd633429187392227f2fa61885;p=python_utils.git diff --git a/smart_future.py b/smart_future.py index e4832d4..7dbec50 100644 --- a/smart_future.py +++ b/smart_future.py @@ -6,6 +6,8 @@ import concurrent.futures as fut import time from typing import Callable, List, TypeVar +# This module is commonly used by others in here and should avoid +# taking any unnecessary dependencies back on them. from deferred_operand import DeferredOperand import id_generator @@ -34,6 +36,16 @@ def wait_any(futures: List[SmartFuture], *, callback: Callable = None): return +def wait_all(futures: List[SmartFuture]) -> None: + done_set = set() + while len(done_set) < len(futures): + for future in futures: + i = future.get_id() + if i not in done_set and future.wrapped_future.done(): + done_set.add(i) + time.sleep(0.1) + + class SmartFuture(DeferredOperand): """This is a SmartFuture, a class that wraps a normal Future and can then be used, mostly, like a normal (non-Future) identifier.