Wait for all tasks to finish.

@param futures
@return true if all tasks returned true or false otherwise.
503159
private boolean waitForTasksToFinish() throws Exception {
        
        Boolean succeeded = true;
        
        // Tracking state for multiple exceptions, if any
        List<StackTraceElement> stackTraces = new ArrayList<StackTraceElement>();
        StringBuilder sb = new StringBuilder();
        int exCount = 0;
        
        for (Future<Boolean> future : futures) {
            try {
                if (!future.get()) {
                    cancel();
                    succeeded = false;
                }
            }
            catch (Exception e) {
                error.compareAndSet(null, e);
                cancel();
                succeeded = false;
                
                exCount++;
                sb.append("ex" + exCount + ": ").append(e.getMessage()).append("\n");
                StackTraceElement[] stackTrace = e.getStackTrace();
                if (stackTrace != null && stackTrace.length > 0) {
                    StackTraceElement delimiterSE = new StackTraceElement("StackTrace: ex" + exCount, "", "", 0);
                    stackTraces.add(delimiterSE);
                    for (StackTraceElement se : stackTrace) {
                        stackTraces.add(se);
                    }
                }
            }
        }
        
        if (this.rowFunction instanceof Flushable) {
            ((Flushable)rowFunction).flush();
        }
        
        if (exCount > 0) {
            String exMessage = sb.toString();
            StackTraceElement[] seArray = stackTraces.toArray(new StackTraceElement[stackTraces.size()]);
            Exception ex = new Exception(exMessage);
            ex.setStackTrace(seArray);
            throw ex;
        }
        return succeeded;
    }
1045929
def wait_for_futures(self):
        
        [future for future in futures.as_completed(self.futures)]
        self.futures = []
377918
protected static boolean loadResourcesAndWaitHelper(final Future f) {
    if (f == null)
      return false;
    try {
      Object o = f.get();
      return true;
    } catch(CancellationException t) {
      return false;
    } catch(ExecutionException t) {
      return false;
    } catch(InterruptedException t) {
      return false;
    }
  }
412549
private Set<Location> waitForTasksCompleted() {
        try {
            Set<Location> targets = new HashSet<>();
            FutureTask<Set<Location>> task;
            while ((task = tasks.poll()) != null) {
                // wait for completion
                if (!task.isDone())
                    targets.addAll(task.get());
            }
            return targets;
        } catch (InterruptedException|ExecutionException e) {
            throw new Error(e);
        }
    }
328815
public void awaitSynchronous() {
    List<CompletableFuture<Void>> futures = pending.get();
    if (futures.isEmpty()) {
      return;
    }
    try {
      CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).join();
    } catch (CompletionException e) {
      logger.log(Level.WARNING, null, e);
    } finally {
      futures.clear();
    }
  }
352919
@Override
    public <T> Future<T> submit(Callable<T> task) {
        try {
            if (this.concurrentExecutor instanceof ExecutorService) {
                return ((ExecutorService) this.concurrentExecutor).submit(task);
            } else {
                FutureTask<T> future = new FutureTask<T>(task);
                this.concurrentExecutor.execute(future);
                return future;
            }
        } catch (RejectedExecutionException ex) {
            throw new TaskRejectedException("Executor [" + this.concurrentExecutor + "] did not accept task: " + task,
                    ex);
        }
    }
27941
public static <T> Future<T> submit(Callable<T> task) {
		return executor.submit(task);
	}
299050
public static <T> Future<T> execAsync(Callable<T> task) {
		return GlobalThreadPool.submit(task);
	}
1246594
public<V> Future<V> submit(Callable<V> task)
    {
        Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed");

        InternalFutureTask<V> futureTask = new InternalFutureTask<V>(new FutureTask<V>(task));
        executorService.execute(futureTask);
        return futureTask;
    }
1139022
def wait_for_a_future(futures, print_traceback=False):
    
    while True:
        try:
            future = next(concurrent.futures.as_completed(futures, timeout=THREAD_TIMEOUT_MAX))
            break
        except concurrent.futures.TimeoutError:
            pass
        except KeyboardInterrupt:
            if print_traceback:
                traceback.print_stack()
            else:
                print('')
            os._exit(os.EX_IOERR)

    return future
446259
public boolean handleNextTask() {
		Runnable task = this.getNextTask();

		if (task != null) {
			synchronized (this.tasksReachesZero) {
				this.runningTasks++;
			}
			try {
				task.run();
			} catch (Throwable t) {
				t.printStackTrace();
			}

			synchronized (this.tasksReachesZero) {
				this.runningTasks--;
				if (this.runningTasks == 0) {
					this.tasksReachesZero.notifyAll();
				}
			}

			synchronized (task) {
				task.notifyAll();
			}
			return true;
		}
		return false;
	}
924516
public static void checkAllDone(Collection<Future> futures) throws Exception {
        for (Future f : futures) {
            if (f.isDone()) {
                f.get();
            }
        }
    }
122406
public static <T> IPromise<IPromise<T>[]> all(IPromise<T>... futures) {
        Promise res = new Promise();
        awaitSettle(futures, res);
        return res;
    }
329800
public void waitUntilFinished()
    {
        flushTermination();
        flushUpdate();
        flushInsert();
        shutdown();
        for (int i = 0; i < numberOfQueues; i++)
        {
            while (!executors[i].isTerminated())
            {
                try
                {
                    executors[i].awaitTermination(10000000, TimeUnit.SECONDS);
                }
                catch (InterruptedException e)
                {
                    // ignore
                }
            }
        }
        if (useBulkInsert)
        {
            bulkInsert();
        }
        logFinalResults();
        if (this.error != null)
        {
            if (error instanceof RuntimeException)
            {
                throw (RuntimeException) error;
            } else
            {
                throw new RuntimeException("One or more parallel tasks failed", this.error);
            }
        }
    }
319336
public List<Future<T>> execute(@SuppressWarnings("unchecked") Task<T> ... tasks) {
		List<Future<T>> futures = new ArrayList<Future<T>>();
		if(tasks != null) {
			synchronized(queue) {
				int i = 0;
				for(Task<T> task : tasks) {
					if(task !=  null) {
						this.tasks.add(task);
						TaskCallable<T> callable = new TaskCallable<T>(i++, queue, task);
						for(TaskObserver<T> observer : observers) {
							observer.onTaskStarting(task);
						}
						futures.add(executor.submit(callable));
						for(TaskObserver<T> observer : observers) {
							observer.onTaskStarted(task);
						}
					}
				}
			}
		}
		return futures;
	}
316907
def _future_completed(future):
    
    exc = future.exception()
    if exc:
        log.debug("Failed to run task on executor", exc_info=exc)
470619
public void waitForTasks() throws IOException {
    // Wait for all submitted tasks to complete
    boolean wasInterrupted = false;
    IOException exception = null;
    for (NamedFuture future : this.futures) {
      try {
        if (wasInterrupted) {
          future.getFuture().cancel(true);
        } else {
          future.getFuture().get();
        }
      } catch (InterruptedException ie) {
        LOGGER.warn("Task was interrupted: " + future.getName());
        wasInterrupted = true;
        if (exception == null) {
          exception = new IOException(ie);
        }
      } catch (ExecutionException ee) {
        LOGGER.warn("Task failed: " + future.getName(), ee.getCause());
        if (exception == null) {
          exception = new IOException(ee.getCause());
        }
      }
    }
    if (wasInterrupted) {
      Thread.currentThread().interrupt();
    }
    if (exception != null && this.failPolicy == FailPolicy.FAIL_ONE_FAIL_ALL) {
      throw exception;
    }

    // clear so that more tasks can be submitted to this ParallelRunner
    futures.clear();
  }