Skip to content

Conversation

@artemredkin
Copy link
Collaborator

@artemredkinartemredkin commented Aug 6, 2020

🚧 This is slightly WIP.
Revamps StreamWriter.

Motivation:
There are two issues with current StreamWriter API:

  1. no access to allocator
  2. writer completion is super confusing, it will be considered finished when the returned EventLoopFuture is completed, which is not ideal.

Modifications:

  1. Deprecate old StreamWriter API
  2. Introduce new type StreamWriter2 (really need help with the naming here) with the following API:
letbody:HTTPClient.Body=.stream2(length:8){ writer in writer.write(writer.allocator.buffer(string:"1234").whenComplete { _ in writer.write(writer.allocator.buffer(string:"1234").whenComplete{ _ in writer.end()}}}

Result:
Closes#194
Closes#264

@artemredkinartemredkin added this to the 1.2.0 milestone Aug 6, 2020
@artemredkinartemredkinforce-pushed the revamp_stream_writer branch 2 times, most recently from 5924d12 to 0cb498aCompareAugust 6, 2020 16:09
/// - length: Body size. Request validation will be failed with `HTTPClientErrors.contentLengthMissing` if nil,
/// unless `Transfer-Encoding: chunked` header is set.
/// - stream: Body chunk provider.
publicstaticfunc stream2(length:Int?=nil, _ stream:@escaping(StreamWriter2)->Void)->Body{
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I we add method with the same name but different type we will break compilation, because some calls could become ambiguous 😢

Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that there is discussion about possibly breaking API in the nearish future anyway, we may find we want to delay this until then to resolve this problem.

@artemredkinartemredkin modified the milestones: 1.2.0, 1.3.0Aug 7, 2020
publicstructStreamWriter2{
publicletallocator:ByteBufferAllocator
letonChunk:(IOData)->EventLoopFuture<Void>
letonComplete:EventLoopPromise<Void>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we're writing this as a callback-taking type rather than just holding onto the task object?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

and "forward" all write requests to it's channel? that might be a good idea, will try that, thanks!

/// - length: Body size. Request validation will be failed with `HTTPClientErrors.contentLengthMissing` if nil,
/// unless `Transfer-Encoding: chunked` header is set.
/// - stream: Body chunk provider.
publicstaticfunc stream2(length:Int?=nil, _ stream:@escaping(StreamWriter2)->Void)->Body{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that there is discussion about possibly breaking API in the nearish future anyway, we may find we want to delay this until then to resolve this problem.

@ktosoktoso changed the base branch from master to mainAugust 20, 2020 01:31
@ktoso
Copy link
Contributor

Just as a heads up, the main development branch has been changed to main, following the Swift policy on this.

This PR has been re-targeted to main and should just work. However when performing rebases etc please keep this in mind -- you may want to fetch the main branch and rebase onto the main branch from now on since master is not up-to-date anymore and is going to be deleted shortly.

@weissiweissi mentioned this pull request Aug 16, 2021
Sign up for freeto 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.

StreamWriter API revamp: access to ByteBufferAllocator unclear docs: How to signal to StreamWriter that body is done?

3 participants

@artemredkin@ktoso@Lukasa