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

Add streaming upload #194

Merged
merged 1 commit into from
Dec 10, 2016
Merged

Add streaming upload #194

merged 1 commit into from
Dec 10, 2016

Conversation

rozap
Copy link
Contributor

@rozap rozap commented Dec 1, 2016

  • Body for put/post/patch can be a {:stream, enumerable}
  • Stream.transform puts bytes into the socket lazily,
    halting at the first error and emitting that error

TODO: Not sure what the best way to test a call to send_body failing while the stream is being transformed, any thoughts here? Right now there's only a test for the non-failure case.

* Body for put/post/patch can be a {:stream, enumerable}
* Stream.transform puts bytes into the socket lazily,
  halting at the first error and emitting that error
@edgurgel
Copy link
Owner

edgurgel commented Dec 4, 2016

Thanks for the PR. Sorry for the delay.

I will give it a try later today and see how we can deal with errors etc. Thank you very much! 👍

_, :error -> {:halt, :error}
bin, :ok -> {[], :hackney.send_body(ref, bin)}
_, error -> {[error], :error}
end) |> Enum.into([])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if I understood well we always "materialise" the stream to become a list before sending? Then we are not going to "stream" the upload as it will be in memory before sending the request.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying that I'm not sure how we would actually stream the data..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Enum.into here to build a list of failures. On the happy path, it only emits empty list to Stream.transform after sending the body, so we're not materializing the list before sending. On the failure side it emits the error, and then changes the state to :error so the error can get emitted and then the stream halts on the next go round.

This is why I'm not using Stream.run here - we want the failure back in the case that something goes wrong.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! I completely misunderstood your code :P

@edgurgel edgurgel merged commit 90ab990 into edgurgel:master Dec 10, 2016
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 this pull request may close these issues.

2 participants