Skip to content

support URLSession concurrency method in Swift 6(Linux, Windows) #58

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 7 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Package.resolved

# DocC generated files
.docc-build
DerivedData
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you move it up to the Xcode section and delete one of the .xcodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it under .xcode

13 changes: 12 additions & 1 deletion Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private enum HTTPTypeConversionError: Error {

#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || compiler(>=6)

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension URLSession {
Expand Down Expand Up @@ -113,7 +113,14 @@ extension URLSession {
}
return (location, response)
}
}

#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
Copy link

Choose a reason for hiding this comment

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

Can we guard only the bytes func with this directive? That way we don't have to do the #endif/#if and split the extension. LGTM otherwise!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it all together in one extension.


@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension URLSession {
Copy link
Contributor Author

@zunda-pixel zunda-pixel Jul 15, 2024

Choose a reason for hiding this comment

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

AsyncBytes supports Apple Platform, but doesn't support Linux and Windows.
swiftlang/swift-corelibs-foundation#3036

/// Returns a byte stream that conforms to AsyncSequence protocol.
///
/// - Parameter request: The `HTTPRequest` for which to load data.
Expand All @@ -131,6 +138,10 @@ extension URLSession {
}
}

#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || compiler(>=6)

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension URLSession {
/// Convenience method to load data using an `HTTPRequest`; creates and resumes a `URLSessionDataTask` internally.
Expand Down