-
Notifications
You must be signed in to change notification settings - Fork 119
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
Finch.stream, again #236
Comments
Due to connection pooling and the state in the connection, it is not trivial to support this type of streaming. If you want lazy streaming, then |
Thanks for chiming in @josevalim ! |
@josevalim Yes, we've discussed, but the previous time the issue was closed due to new approach for streaming. This approach is discussed in #235 and it is an antipattern. I still demand for a proper streaming API, since existing solution with callbacks requires me to re-copy every part of the body to form a stream using send/receive, which is just unnecessary (and it's also the point why solutions like Mint and NimblePool exist in the first place). So, even if you don't have a solution right now, or not planning to implement it in the future, it is definitely worth to have this issue open to track progress and ideas if someone will have a time to implement it. @sneako , please, reopen. My first suggestion
conn = NimblePool.manual_checkout(...)
do_stream(conn)
|> Stream.concat(Stream.resource(fn -> :ok end, fn _ -> {:halt, _} end, fn _ -> NimblePool.manual_checkin(conn) end)) My second suggestionowner = self()
holder =
spawn_link fn -> NimblePool.checkout!(..., fn conn ->
send(owner, conn)
receive do
:release -> :ok
end
end)
conn =
receive do
conn -> conn
end
do_stream(conn)
|> Stream.concat(Stream.resource(fn -> :ok end, fn _ -> {:halt, _} end, fn _ -> send(holder, :release) end))
It is missing timeouts, refs and other stuff. My point is just to share an idea |
As the creator of NimblePool I don't see how to implement solution 1 without adding tons of complexity to the project. I will be glad to be proven wrong. And solution 2 could easily be added on top of the One alternative is to have an option to Of course, it is @sneako's project to manage, but again, I don't see a reason to keep a feature request open which has been extensively discussed before and we don't have known acceptable solutions for. I would rather focus on actionable ones. Regardless, as open source users, we are not in position to demand something. At best we can ask politely and/or fork. :) |
I've been thinking about this since seeing these issues raised by @hissssst a few days ago and here are some thoughts:
|
No, it can't. The only possible solution with |
Ah, I missed that. But even that assumes the connection will be happy to be transferred to another process and that there will be no leakage in case of errors. Feel free to explore that, it may provide an alternative path we haven't considered, but please double check both NimblePool and Mint will be happy with the resource transfer under several different scenarios. Then it can even be the sketch of a PR we could all collaborate on. |
@sneako , if you reopen this, I will provide a PR for the issue in a few days or so. |
@hissssst ping? :) |
Pong, I was having a vacation and switching jobs. This issue is somewhere in my TODO, but I don't have a free time to do this in a next two weeks or so. |
@hissssst 🛎️ it would be great to have this some day :) |
Implementation for HTTP1 is on the way, but HTTP2 won't be implemented until the critical issue #282 gets fixed |
Given what was said in #235, it would be nice to have a function
Which would
Stream.t()
{:status, pos_integer()} | {:header, name :: binary(), value :: binary()} | {:body, binary()}
The text was updated successfully, but these errors were encountered: