Skip to content

Make new async/await API public #552

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

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension HTTPClient {
/// - deadline: Point in time by which the request must complete.
/// - logger: The logger to use for this request.
/// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received.
func execute(
public func execute(
_ request: HTTPClientRequest,
deadline: NIODeadline,
logger: Logger? = nil
Expand All @@ -52,7 +52,7 @@ extension HTTPClient {
/// - timeout: time the the request has to complete.
/// - logger: The logger to use for this request.
/// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received.
func execute(
public func execute(
_ request: HTTPClientRequest,
timeout: TimeAmount,
logger: Logger? = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
extension HTTPClient {
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func shutdown() async throws {
public func shutdown() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
self.shutdown { error in
switch error {
Expand Down
32 changes: 16 additions & 16 deletions Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import NIOCore
import NIOHTTP1

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
struct HTTPClientRequest {
var url: String
var method: HTTPMethod
var headers: HTTPHeaders
public struct HTTPClientRequest {
public var url: String
public var method: HTTPMethod
public var headers: HTTPHeaders

var body: Body?
public var body: Body?

init(url: String) {
public init(url: String) {
self.url = url
self.method = .GET
self.headers = .init()
Expand All @@ -34,7 +34,7 @@ struct HTTPClientRequest {

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientRequest {
struct Body {
public struct Body {
@usableFromInline
internal enum Mode {
case asyncSequence(length: RequestBodyLength, (ByteBufferAllocator) async throws -> ByteBuffer?)
Expand All @@ -54,12 +54,12 @@ extension HTTPClientRequest {

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientRequest.Body {
static func bytes(_ byteBuffer: ByteBuffer) -> Self {
public static func bytes(_ byteBuffer: ByteBuffer) -> Self {
self.init(.byteBuffer(byteBuffer))
}

@inlinable
static func bytes<Bytes: RandomAccessCollection>(
public static func bytes<Bytes: RandomAccessCollection>(
_ bytes: Bytes
) -> Self where Bytes.Element == UInt8 {
self.init(.sequence(
Expand All @@ -76,7 +76,7 @@ extension HTTPClientRequest.Body {
}

@inlinable
static func bytes<Bytes: Sequence>(
public static func bytes<Bytes: Sequence>(
_ bytes: Bytes,
length: Length
) -> Self where Bytes.Element == UInt8 {
Expand All @@ -94,7 +94,7 @@ extension HTTPClientRequest.Body {
}

@inlinable
static func bytes<Bytes: Collection>(
public static func bytes<Bytes: Collection>(
_ bytes: Bytes,
length: Length
) -> Self where Bytes.Element == UInt8 {
Expand All @@ -112,7 +112,7 @@ extension HTTPClientRequest.Body {
}

@inlinable
static func stream<SequenceOfBytes: AsyncSequence>(
public static func stream<SequenceOfBytes: AsyncSequence>(
_ sequenceOfBytes: SequenceOfBytes,
length: Length
) -> Self where SequenceOfBytes.Element == ByteBuffer {
Expand All @@ -124,7 +124,7 @@ extension HTTPClientRequest.Body {
}

@inlinable
static func stream<Bytes: AsyncSequence>(
public static func stream<Bytes: AsyncSequence>(
_ bytes: Bytes,
length: Length
) -> Self where Bytes.Element == UInt8 {
Expand Down Expand Up @@ -157,11 +157,11 @@ extension Optional where Wrapped == HTTPClientRequest.Body {

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientRequest.Body {
struct Length {
public struct Length {
/// size of the request body is not known before starting the request
static let unknown: Self = .init(storage: .unknown)
public static let unknown: Self = .init(storage: .unknown)
/// size of the request body is fixed and exactly `count` bytes
static func known(_ count: Int) -> Self {
public static func known(_ count: Int) -> Self {
.init(storage: .known(count))
}

Expand Down
20 changes: 10 additions & 10 deletions Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import NIOCore
import NIOHTTP1

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
struct HTTPClientResponse {
var version: HTTPVersion
var status: HTTPResponseStatus
var headers: HTTPHeaders
var body: Body
public struct HTTPClientResponse {
public var version: HTTPVersion
public var status: HTTPResponseStatus
public var headers: HTTPHeaders
public var body: Body

struct Body {
public struct Body {
private let bag: Transaction
private let reference: ResponseRef

Expand All @@ -48,21 +48,21 @@ struct HTTPClientResponse {

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientResponse.Body: AsyncSequence {
typealias Element = AsyncIterator.Element
public typealias Element = AsyncIterator.Element

struct AsyncIterator: AsyncIteratorProtocol {
public struct AsyncIterator: AsyncIteratorProtocol {
private let stream: IteratorStream

fileprivate init(stream: IteratorStream) {
self.stream = stream
}

mutating func next() async throws -> ByteBuffer? {
public mutating func next() async throws -> ByteBuffer? {
try await self.stream.next()
}
}

func makeAsyncIterator() -> AsyncIterator {
public func makeAsyncIterator() -> AsyncIterator {
AsyncIterator(stream: IteratorStream(bag: self.bag))
}
}
Expand Down