diff --git a/src/main/java/conseq4j/execute/ConseqExecutor.java b/src/main/java/conseq4j/execute/ConseqExecutor.java index a49bfcf..8835096 100644 --- a/src/main/java/conseq4j/execute/ConseqExecutor.java +++ b/src/main/java/conseq4j/execute/ConseqExecutor.java @@ -142,13 +142,13 @@ private static ConditionFactory await() { public @NonNull Future submit(@NonNull Callable task, @NonNull Object sequenceKey) { CompletableFuture taskCompletable = activeSequentialTasks.compute( sequenceKey, - (k, presentTask) -> (presentTask == null) + (k, vCompletable) -> (vCompletable == null) ? CompletableFuture.supplyAsync(() -> callUnchecked(task), workerExecutorService) - : presentTask.handleAsync((r, e) -> callUnchecked(task), workerExecutorService)); + : vCompletable.handleAsync((r, e) -> callUnchecked(task), workerExecutorService)); CompletableFuture copy = taskCompletable.thenApply(r -> r); taskCompletable.whenCompleteAsync( (r, e) -> activeSequentialTasks.computeIfPresent( - sequenceKey, (k, checkedTask) -> checkedTask.isDone() ? null : checkedTask), + sequenceKey, (k, vCompletable) -> vCompletable.isDone() ? null : vCompletable), adminService); return (Future) new DefensiveFuture<>(copy); }