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

Support for async interface #115

Open
silviucpp opened this issue Jun 28, 2021 · 5 comments
Open

Support for async interface #115

silviucpp opened this issue Jun 28, 2021 · 5 comments

Comments

@silviucpp
Copy link

Hello,

Right now the API provides only methods that blocks the current process until the response is received. Can you add API's that sends the response when is ready to a specified PID ?

Silviu

@puzza007
Copy link
Owner

It's certainly possible. At the moment it uses https://erlang.org/doc/man/gen_server.html#reply-2 to make synchronous responses. Do you have an existing asynch API in mind?

@silviucpp
Copy link
Author

silviucpp commented Jun 29, 2021

I'm thinking that inside the request options to add:

  • async = true| false (default is false to work as it is now)
  • reply_to = any pid (default to self())

And when async = true the katipo:req to return {ok, ResponseReference::ref()}

Once the response is available the process indicated in reply_to to receive a message like:

{katipo_resp, ResponseReference, Response} where ResponseReference to be the one you returned in the request and
Response to be the HTTP call response:

#{status := 200,
       headers := RespHeaders,
       cookiejar := CookieJar,
       body := RespBody}

or whatever katipo:req returns normally when using sync calls.

What do you think ?

Silviu

@puzza007
Copy link
Owner

puzza007 commented Jul 1, 2021

Cool so basically something like https://github.com/benoitc/hackney#get-a-response-asynchronously 👍

@silviucpp
Copy link
Author

@puzza007 I honestly inspired myself from https://github.com/lpgauth/buoy . Difference is that in buoy you get on single message at the end of the response with the response. In hackney you get multiple messages progressively like: when you get the headers, when you get the body and one at the final... This makes most of the use cases complicated because you have to aggregate yourself everything and when the done response comes you know you have the response.

puzza007 added a commit that referenced this issue Jul 1, 2021
@puzza007
Copy link
Owner

puzza007 commented Jul 1, 2021

Cool. I've started a branch with some very early work. I haven't got it running yet.

puzza007 added a commit that referenced this issue Feb 22, 2022
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 a pull request may close this issue.

2 participants