Skip to content

Conversation

@oscerd
Copy link

@oscerd oscerd commented Dec 12, 2025

This should fix #127

@oscerd oscerd changed the title Add Async support feat: Add Async support Dec 12, 2025
@oscerd oscerd closed this Dec 12, 2025
@oscerd oscerd reopened this Dec 12, 2025
@oscerd
Copy link
Author

oscerd commented Dec 12, 2025

@edeandrea @ThomasVitale

@github-actions
Copy link

github-actions bot commented Dec 12, 2025

:java_duke: JaCoCo coverage report

Overall Project 42.01% 🔴

There is no coverage information present for the Files changed

@github-actions
Copy link

github-actions bot commented Dec 12, 2025

TestsPassed ✅SkippedFailed
Gradle Test Results (all modules & JDKs)633 ran633 passed0 skipped0 failed
TestResult
No test annotations available

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@oscerd
Copy link
Author

oscerd commented Dec 12, 2025

No worries. Enjoy the weekend!

Copy link
Contributor

@edeandrea edeandrea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few general comments about how I envisioned the async to work. I was thinking that we would return CompletableFuture objects in the async operations. This would solve a number of issues, but the biggest is that the current implementation polls on the same thread that that it executes the task from. This could lead to deadlock in systems that are not thread-per-request.

Plus other downstream implementors may want to use virtual threads or some other threading mechanism.

Sticking to CompletableFuture allows more more customization by downstream frameworks.

@ThomasVitale thoughts?

@oscerd
Copy link
Author

oscerd commented Dec 13, 2025

I proposed a new solution with CompletableFuture. If it works for all I'll change to Duration the missing field and add the section to whats new.

Copy link
Contributor

@edeandrea edeandrea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments on the DoclingServeConvertApi

I think we only need a single method:

CompletableFuture<ConvertDocumentResponse> convertSource(ConvertDocumentRequest request);

The implementation of that method would handle all the necessary polling to return the completed future once its complete.

At least that was my vision. Thoughts @ThomasVitale ?

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@oscerd
Copy link
Author

oscerd commented Dec 13, 2025

I guess I'll need to tackle this from scratch again. I was porting the logic coming from Camel, so I could have miss some parts of the API on this side. I'll rework on this next week.

@edeandrea
Copy link
Contributor

I think it's actually simpler than you realize. All the polling apis are already there, plus you already have the logic for polling based on a duration. It's just providing a method which ties everything together.

@oscerd oscerd force-pushed the 127 branch 2 times, most recently from 02759ae to 33f4cea Compare December 15, 2025 08:52
@oscerd
Copy link
Author

oscerd commented Dec 15, 2025

It should be better now. I spent an hour or so looking at the API a bit deeper.

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

Copy link
Contributor

@edeandrea edeandrea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I hope you don't mind but I made a few tweaks. CompletableFuture has built-in polling capabilities, so you don't need to create your own polling executor. (see f5033ac)

I also added the polling properties to the DoclingServeApi builder so it can be configured by any client implementing the api.

@oscerd @ThomasVitale Have a look and let me know what you think.

@oscerd
Copy link
Author

oscerd commented Dec 15, 2025

Looks good! I hope you don't mind but I made a few tweaks. CompletableFuture has built-in polling capabilities, so you don't need to create your own polling executor. (see f5033ac)

I also added the polling properties to the DoclingServeApi builder so it can be configured by any client implementing the api.

@oscerd @ThomasVitale Have a look and let me know what you think.

Looks really better know. I think I should revisit a bit the Async API for Java, it's been a while.. thanks for completing the PR. +1 from my side.

@edeandrea
Copy link
Contributor

I think I should revisit a bit the Async API for Java, it's been a while.

Its been a while for me too, at least with "vanilla" Java (I'm so used to Mutiny/etc). Was a good learning exercise for me too!

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@ThomasVitale
Copy link
Contributor

I'll review the new changes later today

oscerd and others added 2 commits December 15, 2025 10:57
Signed-off-by: Andrea Cosentino <[email protected]>
Simplified the async polling logic in `ConvertOperations` by replacing the custom scheduler with `CompletionStage` chaining. Improved task status handling by centralizing logic for success, failure, and retry behavior. Cleaned up imports and adjusted tests to maintain consistency with updated logic.

Signed-off-by: Eric Deandrea <[email protected]>
@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

* {@link CompletableFuture} that completes when the conversion is done.
*
* <p>This method starts the conversion, polls the status in the background, and completes
* the future with the result when the conversion finishes. The polling happens on a separate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should remove this final sentence as it's up to the framework/client to configure how the polling happens (platform thread, virtual thread, some other mechanism provided by Mutiny/Reactor). Thoughts?

@ThomasVitale
Copy link
Contributor

Looks good to me! Just left a couple of comments about the docs. I like the clean API returning CompletableFuture and allowing clients/frameworks to adapt it to different asynchronous setups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add async support

3 participants