Skip to content

Commit

Permalink
Merge pull request #6 from MFB-Technologies-Inc/bugfix/async-beta-doe…
Browse files Browse the repository at this point in the history
…s-not-support-urlsessiondelegate
  • Loading branch information
roanutil authored Feb 8, 2023
2 parents c8ffdc2 + 39a21c9 commit 71806bf
Show file tree
Hide file tree
Showing 56 changed files with 90 additions and 88 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ jobs:
- '12.5.1'
- '13.2'
- '13.4'
- '14.0'
- '14.0.1'
- '14.1'
- '14.2'
exclude:
- os: macos-11
xcode: '13.2'
- os: macos-11
xcode: '13.4'
- os: macos-11
xcode: '14.0'
xcode: '14.0.1'
- os: macos-11
xcode: '14.1'
- os: macos-11
xcode: '14.2'
- os: macos-12
xcode: '12.4'
- os: macos-12
Expand Down
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/pointfreeco/combine-schedulers.git",
"state": {
"branch": null,
"revision": "aa3e575929f2bcc5bad012bd2575eae716cbcdf7",
"version": "0.8.0"
"revision": "882ac01eb7ef9e36d4467eb4b1151e74fcef85ab",
"version": "0.9.1"
}
},
{
Expand All @@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state": {
"branch": null,
"revision": "30314f1ece684dd60679d598a9b89107557b67d9",
"version": "0.4.1"
"revision": "ace21305e0dd3a9e749aef79fef14be79a3b4669",
"version": "0.8.2"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/HTTPURLResponse+StatusCode.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// HTTPURLResponse+StatusCode.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkService.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient+Delete.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Delete.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient+Get.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Get.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+GetSession.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient+Post.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Post.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient+Put.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Put.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient+Start.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Start.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+URLSessionDelegate.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkServiceClient.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/Publisher+NetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Publisher+NetworkService.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/TopLevelCodable.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TopLevelCodable.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/URLRequest+HTTPHeader.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// URLRequest+HTTPHeader.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/URLRequest+HTTPMethod.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// URLRequest+HTTPMethod.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// HTTPURLResponse+StatusCode.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceAsyncBeta/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkService.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Delete.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Get.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+GetSession.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Post.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Put.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
54 changes: 25 additions & 29 deletions Sources/NetworkServiceAsyncBeta/NetworkServiceClient+Start.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Start.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -28,38 +28,34 @@ extension NetworkServiceClient {

private func response(_ request: URLRequest) async throws -> (Data, URLResponse) {
let session = getSession()
if #available(iOS 15, watchOS 8, macOS 12, macCatalyst 15, tvOS 15, *) {
return try await session.data(for: request)
} else {
var task: URLSessionDataTask?
var shouldCancel: Bool = false
let onCancel = {
if let task = task {
task.cancel()
} else {
shouldCancel = true
}
var task: URLSessionDataTask?
var shouldCancel: Bool = false
let onCancel = {
if let task = task {
task.cancel()
} else {
shouldCancel = true
}
return try await withTaskCancellationHandler(
handler: { onCancel() },
operation: {
try await withCheckedThrowingContinuation { continuation in
task = session.dataTask(with: request, completionHandler: { _data, _urlResponse, _error in
guard let data = _data, let urlResponse = _urlResponse else {
return continuation.resume(throwing: _error ?? URLError(.badServerResponse))
}
continuation.resume(returning: (data, urlResponse))
})

if shouldCancel {
task?.cancel()
} else {
task?.resume()
}
return try await withTaskCancellationHandler(
handler: { onCancel() },
operation: {
try await withCheckedThrowingContinuation { continuation in
task = session.dataTask(with: request, completionHandler: { _data, _urlResponse, _error in
guard let data = _data, let urlResponse = _urlResponse else {
return continuation.resume(throwing: _error ?? URLError(.badServerResponse))
}
continuation.resume(returning: (data, urlResponse))
})

if shouldCancel {
task?.cancel()
} else {
task?.resume()
}
}
)
}
}
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceAsyncBeta/NetworkServiceClient.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Result+NetworkService.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceAsyncBeta/TopLevelCodable.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TopLevelCodable.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// URLRequest+HTTPHeader.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// URLRequest+HTTPMethod.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceAsyncBeta/URLRequest+build.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// URLRequest+build.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceTestHelper/MockNetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// MockNetworkService.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// CodableOutput.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkServiceTestHelperAsyncBeta/Delay.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Delay.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// FailureOutput.swift
// NetworkService
//
// Copyright © 2022 MFB Technologies, Inc. All rights reserved.
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
Loading

0 comments on commit 71806bf

Please sign in to comment.