Add support for custom Executor
Currently all the blocking API methods run on the calling thread, and the async methods run on the fork-join pool. We should allow for passing in (or building the client) with a custom Executor for async operations.
Hi @edeandrea, I'd like to work on this. Proposed design: add asyncExecutor(Executor) to DoclingApiBuilder; the client uses it for every async step (task submission, status polling incl. the delayed re-poll via the 3-arg CompletableFuture.delayedExecutor, and result retrieval). Default stays CompletableFuture's default executor so nothing changes unless it's set, toBuilder() carries it over, and the client never shuts the executor down. One question: since asyncExecutor would be a new abstract method on the builder interface, would you prefer a default method to avoid breaking third-party builders? I have a working branch with WireMock-based tests and can open a PR if this direction works for you.
Hi @edeandrea, I'd like to work on this. Proposed design: add
asyncExecutor(Executor)toDoclingApiBuilder; the client uses it for every async step (task submission, status polling incl. the delayed re-poll via the 3-argCompletableFuture.delayedExecutor, and result retrieval). Default staysCompletableFuture's default executor so nothing changes unless it's set,toBuilder()carries it over, and the client never shuts the executor down. One question: sinceasyncExecutorwould be a new abstract method on the builder interface, would you prefer adefaultmethod to avoid breaking third-party builders? I have a working branch with WireMock-based tests and can open a PR if this direction works for you.
Hi @Naman-Gururani thanks for wanting to work on this!
I like the design, adding asyncExecutor to DoclingApiBuilder would be great!
The only change I would might make is defaulting to ForkJoinPool.commonPool() (since that's the default if no pool is supplied).
As to breaking, adding a new method to a builder isn't a breaking change, especially if it defaults to ForkJoinPool.commonPool(). The builder pattern is 100% additive at that point while still allowing for downstream customization.
As for testing, please follow the testing pattern(s) already established in this project (there are wiremock & testcontainers tests).
🎉 This issue has been resolved in v0.7.0 (Release Notes)