-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Separate out resolve request (#36)
Co-authored-by: danthorpe <[email protected]>
- Loading branch information
Showing
8 changed files
with
106 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Dependencies | ||
import Foundation | ||
import Helpers | ||
|
||
extension NetworkingComponent { | ||
|
||
@discardableResult | ||
public func data( | ||
_ request: HTTPRequestData, | ||
progress updateProgress: @escaping @Sendable (BytesReceived) async -> Void = { _ in }, | ||
timeout duration: Duration, | ||
using clock: @autoclosure () -> any Clock<Duration> | ||
) async throws -> HTTPResponseData { | ||
do { | ||
try Task.checkCancellation() | ||
return try await send(request) | ||
.compactMap { element in | ||
await updateProgress(element.progress) | ||
return element.value | ||
} | ||
.first(beforeTimeout: duration, using: clock()) | ||
} catch is TimeoutError { | ||
throw StackError.timeout(request) | ||
} | ||
} | ||
|
||
@discardableResult | ||
public func data( | ||
_ request: HTTPRequestData, | ||
progress updateProgress: @escaping @Sendable (BytesReceived) async -> Void = { _ in }, | ||
timeout duration: Duration | ||
) async throws -> HTTPResponseData { | ||
try await data( | ||
request, | ||
progress: updateProgress, | ||
timeout: duration, | ||
using: Dependency(\.continuousClock).wrappedValue | ||
) | ||
} | ||
|
||
@discardableResult | ||
public func data( | ||
_ request: HTTPRequestData, | ||
progress updateProgress: @escaping @Sendable (BytesReceived) async -> Void = { _ in } | ||
) async throws -> HTTPResponseData { | ||
try await data( | ||
request, progress: updateProgress, timeout: .seconds(request.requestTimeoutInSeconds)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Foundation | ||
|
||
extension NetworkingComponent { | ||
|
||
public var authority: String { | ||
resolve(HTTPRequestData()).authority | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters