Various changes.
[python_utils.git] / smart_future.py
index e4832d43d5b1674988628e5dae43a67cf8ed0565..7dbec5004b4ba927331e71fb812fd482af678c3c 100644 (file)
@@ -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.