async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

implement new streamwriter api

Open artemredkin opened this issue 5 years ago • 1 comments

🚧 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:
let body: 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

artemredkin avatar Aug 06 '20 16:08 artemredkin

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.

ktoso avatar Aug 20 '20 01:08 ktoso