private @NotNull <Result> CompletableFuture<Result> onValidThread(@NotNull Function<? super Structure, ? extends Result> function) {
    CompletableFuture<Result> future = new CompletableFuture<>();
    invoker.compute(() -> {
      if (!disposed) {
        Result result = function.apply(structure);
        if (result != null) {
          future.complete(result);
        }
      }
      if (!future.isDone()) {
        future.completeExceptionally(AsyncPromise.CANCELED);
      }
      return null;
    }).onError(future::completeExceptionally);
    return future;
  }
private @NotNull <Result> CompletableFuture<Result> onValidThread(@NotNull Function<? super Structure, ? extends Result> function)