public static void join(final Iterable<? extends Future<?>> futures) {
		final Iterator<? extends Future<?>> tasks = futures.iterator();

		Exception exception = null;
		Future<?> future = null;
		try {
			while (tasks.hasNext()) {
				future = tasks.next();
				future.get();
			}
			future = null;
		} catch (InterruptedException |
		         ExecutionException |
		         CancellationException e)
		{
			exception = e;
		}

		// Cancel all remaining tasks, in case of an error.
		if (future != null) {
			future.cancel(true);
			tasks.forEachRemaining(t -> t.cancel(true));
		}

		// Handle exceptions, if any.
		if (exception instanceof InterruptedException ie) {
			Thread.currentThread().interrupt();
			final var ce = new CancellationException(ie.getMessage());
			ce.initCause(ie);
			throw ce;
		} else if (exception instanceof CancellationException e) {
			throw e;
		} else if (exception != null) {
			throw new CompletionException(exception);
		}
	}
Joins the given set of futures.

@param futures the future objects to join.
jenetics/src/main/java/io/jenetics/internal/util/Futures.java