New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal][Client] Consider more idiomatic bridges with JVM async paradigms #565
Comments
@bsless Thanks for this Ben 🙏 So just to check my understanding - there's 2 enhancements being proposed here: Proposal 1
The proposal is to update Is that right? If so, sounds reasonable to me - and shouldn't be difficult - though I'm not familiar off-hand with the particular Proposal 2
One obvious approach would be to add something like Is that the idea? If so, sounds very reasonable to me - and also shouldn't be difficult. If I've got the above ~right, then both sound like nice additions with no obvious downsides - would be happy to look at a PR from you or anyone else that felt like submitting one 👍 |
That's the general thrust, but there are some subtle points (footguns?) for each that should be considered Proposal 1 - CompletableFutureThe CompletableFuture interface is huge. It merges the Future interface which has ~5 methods and the CompletionStage interface which has over 20.
Proposal 2 - success/error callbacksThe problem with directly setting the response handler methods is all the special cases on the success callback which can still error, like too many redirects. |
Thanks for the feedback. I'm currently focused on other topics so my own feedback'll need to be superficial for now- Proposal 1
Is it really necessary to implement so much for the use cases commonly applicable to http-kit client? Have there been any relevant discussions re: Clojure's promise and
I'd rule out the breaking change, and would be hesitant to provide an option that changes the return type. Options like that tend to balloon tests, documentation, examples, etc. It's not out-of-the-question if there's a strong reason to go that route, but my first preference would definitely be to first rule out better alternatives. Proposal 2
To clarify- I don't mean to suggest replacing the current handler methods, just injecting user callbacks into them at the appropriate place - as is done for the current undifferentiated
I'm not too concerned about the particular calling API - I believe that's unrelated to point above. We could easily support both kw and positional args- i.e. something like
|
I'll be optimistic and try to extend CompletableFuture and see if manages to satisfy all requirements. If all turns out well, I'll prepare two draft PRs @borkdude would appreciate your thoughts here, is there anything I'm missing? |
Proposal 3 could maybe be to offer a third party bridge lib between http-kit client + |
Currently, every code using HTTP Kit's client must check and handle the
:error
key in the response, including in asynchronous code.Additionally, the return value from
request
does not "play nice" (explained further) with java.util.concurrent idiomsGiven
This works
This doesn't work
This does work
This works, too
This also requires parsing errors, this would have been nicer
Then request-cf would be implemented in a more straightforward manner
Consuming http kit client from j.u.c would be cleaner / easier if client/request returned a CompletableFuture
It would also be convenient to have a 3 arity version (like ring) which would not require parsing the return value and checking for error, makes error handling explicit, separates error handling code from business logic
That also simplifies writing generic wrappers for HTTP clients independent of their implementation details (instrumentations like metrics, middlewares, etc)
wdyt?
The text was updated successfully, but these errors were encountered: