class FutureUtils {

	public static <IN, OUT> CompletableFuture<OUT> thenComposeAsyncIfNotDone(
		CompletableFuture<IN> completableFuture,
		Executor executor,
		Function<? super IN, ? extends CompletionStage<OUT>> composeFun) {
		return completableFuture.isDone() ?
			completableFuture.thenCompose(composeFun) :
			completableFuture.thenComposeAsync(composeFun, executor);
	}

}