Skip to content
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

HttpClient HTTP request/response API method design that provides non racy methods when called outside event-loop #4705

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vietj
Copy link
Member

@vietj vietj commented May 17, 2023

Racy code called from a non event-loop/worker context thread

// Racy
Future<Buffer> fut = client
   .request(options)
   .compose(req -> req.send())
   .compose(resp -> resp.body());

Instead one should write

// Not racy
Future<Buffer> fut = client
   .request(options)
   .compose(req -> req.send().compose(resp -> resp.body()));

This PR shows a new non racy API design <T> Future<T> request(..., Function<HttpClientRequest, Future<T>>)

// Not racy
Future<Buffer> fut = client.request(options, req -> req
   .send()
   .compose(resp -> resp.body()));

which provides interesting usability:

// Conversion
Future<JsonObject> fut = client.request(options, req -> req
   .send()
   .compose(resp -> resp.body())
   .map(body -> new JsonObject(body)));

@vietj vietj added this to the 5.0.0 milestone May 17, 2023
@vietj vietj changed the title Experiment with HttpClient HTTP request/response API method design that provides non racy methods when called outside event-loop HttpClient HTTP request/response API method design that provides non racy methods when called outside event-loop May 17, 2023
@vietj vietj requested a review from tsegismont May 17, 2023 08:36
@vietj
Copy link
Member Author

vietj commented May 17, 2023

asking for @tsegismont @jponge opinion more than a review

@vietj vietj marked this pull request as draft May 17, 2023 08:37
@tsegismont
Copy link
Contributor

IIUC, the proposed API enforces the non racy usage that is required with the current API (by taking the transformation chain as a parameter).

LGTM, 👍

…at provides non racy methods when called outside event-loop.
@vietj vietj force-pushed the http-client-handler-methods branch from aa6c664 to 9e1e5fb Compare May 17, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants