code: private <T> DeferredAction<M> deferAction(
        final M metadata, final Supplier<? extends CompletionStage<T>> action,
        final CompletableFuture<T> future
    ) {
      return new DeferredAction<>(metadata, () -> {
        final CompletionStage<? extends T> resultFuture;
  
        try {
          resultFuture = action.get();
        } catch (final Exception e) {
          future.completeExceptionally(e);
          markProcessed(metadata);
          return;
        }
  
        resultFuture.handleAsync((result, e) -> {
          if (e != null) {
            future.completeExceptionally(e);
          } else {
            future.complete(result);
          }
  
          markProcessed(metadata);
          return null;
        }, executor);
      });
    }
docs: Defer the given action.
  
  @param metadata metadata associated with the action
  @param action action to defer
  @param future future that will be bound to the action
  @param <T> return type of the action
  @return a deferred action container