-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fixes #7126. #7149
Fixes #7126. #7149
Conversation
Have you considered making So |
I haven't, but that should be considered outside this PR. In all honesty, I'm happy with the current implementation.
In some cases users might like to use the synchronous implementation with threads. I don't think I can return a blocking stream, unless I prevent this functionality. |
Could you clarify how it would work with threads, given the httpclient module uses GCed references, Nim has thread-local GCs, and it's unsafe to access objects from other thread's heap? If you mean they may want to receive data on a separate thread and send it to another thread, then blocking streams should work fine with this use case. Also, this implementation for async client again doesn't really allow to process data in chunks. |
That is what I mean. I'm not sure it's possible to implement chunked processing of data with blocking streams though. If it is then that is a good way to do it.
It does but only if you process the data immediately. Is that really a problem? Delaying the processing of the HTTP body sounds like it would cause issues. |
So I tried to use |
What I meant is a blocking socket stream that directly accesses the socket. Writing into string stream from httpclient and then making user read from it feels hacky to me, both in async and sync versions, as it removes control from the user. You may want to delay reading if you would like to preserve bandwidth. For example, you are doing multiple simultaneous requests with different priorities and you want to throttle low-priority requests based on available bandwidth. Or you are making a file download utility that has download speed limit option (see |
Alright. That's a worthy use case. Let's change That's going to be a much bigger job. |
Other ideas of how this should be implemented are welcome. I'm not entirely happy about my solution:
Synchronous HttpClient has a different API for the streaming of the body to the AsyncHttpClient which is a shame.
Two callbacks to stream data feels ugly to me.