class BulkheadExecutor<R> extends PolicyExecutor<R> {
  private final BulkheadImpl<R> bulkhead;
  private final Duration maxWaitTime;

  public BulkheadExecutor(BulkheadImpl<R> bulkhead, int policyIndex) {
    super(bulkhead, policyIndex);
    this.bulkhead = bulkhead;
    maxWaitTime = bulkhead.getConfig().getMaxWaitTime();
  }

  @Override
  protected ExecutionResult<R> preExecute() {
    try {
      return bulkhead.tryAcquirePermit(maxWaitTime) ?
        null :
        ExecutionResult.exception(new BulkheadFullException(bulkhead));
    } catch (InterruptedException e) {
      // Set interrupt flag
      Thread.currentThread().interrupt();
      return ExecutionResult.exception(e);
    }
  }

  @Override
  protected CompletableFuture<ExecutionResult<R>> preExecuteAsync(Scheduler scheduler, FailsafeFuture<R> future) {<FILL_FUNCTION_BODY>}

  @Override
  public void onSuccess(ExecutionResult<R> result) {
    bulkhead.releasePermit();
  }

  @Override
  protected ExecutionResult<R> onFailure(ExecutionContext<R> context, ExecutionResult<R> result) {
    bulkhead.releasePermit();
    return result;
  }
}

    CompletableFuture<ExecutionResult<R>> promise = new CompletableFuture<>();
    CompletableFuture<Void> acquireFuture = bulkhead.acquirePermitAsync();
    acquireFuture.whenComplete((result, error) -> {
      // Signal for execution to proceed
      promise.complete(ExecutionResult.none());
    });

    if (!promise.isDone()) {
      try {
        // Schedule bulkhead permit timeout
        Future<?> timeoutFuture = scheduler.schedule(() -> {
          promise.complete(ExecutionResult.exception(new BulkheadFullException(bulkhead)));
          acquireFuture.cancel(true);
          return null;
        }, maxWaitTime.toNanos(), TimeUnit.NANOSECONDS);

        // Propagate outer cancellations to the promise, bulkhead acquire future, and timeout future
        future.setCancelFn(this, (mayInterrupt, cancelResult) -> {
          promise.complete(cancelResult);
          acquireFuture.cancel(mayInterrupt);
          timeoutFuture.cancel(mayInterrupt);
        });
      } catch (Throwable t) {
        // Hard scheduling failure
        promise.completeExceptionally(t);
      }
    }

    return promise;
  
<methods>public Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(Function<SyncExecutionInternal<R>,ExecutionResult<R>>, dev.failsafe.spi.Scheduler) ,public Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> applyAsync(Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>>, dev.failsafe.spi.Scheduler, FailsafeFuture<R>) ,public int getPolicyIndex() ,public ExecutionResult<R> postExecute(ExecutionInternal<R>, ExecutionResult<R>) <variables>private final non-sealed EventHandler<R> failureHandler,private final non-sealed FailurePolicy<R> failurePolicy,private final non-sealed int policyIndex,private final non-sealed EventHandler<R> successHandler