File tree Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change 1414
1515// TODO: remove @testable after async/await API is public
1616@testable import AsyncHTTPClient
17- import NIOCore
1817import Foundation
18+ import NIOCore
1919import NIOFoundationCompat
2020
2121#if compiler(>=5.5.2) && canImport(_Concurrency)
Original file line number Diff line number Diff line change @@ -24,13 +24,14 @@ let package = Package(
2424 ] ,
2525 dependencies: [
2626 . package ( url: " https://github.com/apple/swift-nio.git " , . branch( " main " ) ) ,
27-
27+
2828 // in real-world projects this would be
2929 // .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0")
3030 . package ( name: " async-http-client " , path: " ../ " ) ,
3131 ] ,
3232 targets: [
3333 // MARK: - Examples
34+
3435 . executableTarget(
3536 name: " GetHTML " ,
3637 dependencies: [
Original file line number Diff line number Diff line change @@ -27,20 +27,20 @@ struct StreamingByteCounter {
2727 let request = HTTPClientRequest ( url: " https://apple.com " )
2828 let response = try await httpClient. execute ( request, timeout: . seconds( 30 ) )
2929 print ( " HTTP head " , response)
30-
30+
3131 // if defined, the content-length headers announces the size of the body
3232 let expectedBytes = response. headers. first ( name: " content-length " ) . flatMap ( Int . init)
33-
33+
3434 var receivedBytes = 0
3535 // asynchronously iterates over all body fragments
3636 // this loop will automatically propagate backpressure correctly
3737 for try await buffer in response. body {
3838 // For this example, we are just interested in the size of the fragment
3939 receivedBytes += buffer. readableBytes
40-
40+
4141 if let expectedBytes = expectedBytes {
4242 // if the body size is known, we calculate a progress indicator
43- let progress = Double ( receivedBytes) / Double( expectedBytes)
43+ let progress = Double ( receivedBytes) / Double( expectedBytes)
4444 print ( " progress: \( Int ( progress * 100 ) ) % " )
4545 }
4646 // in case backpressure is needed, all reads will be paused until returned future is resolved
You can’t perform that action at this time.
0 commit comments