Skip to content
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

Fix concurrency warnings in tests #38

Merged
merged 2 commits into from
Oct 31, 2024
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: 4 additions & 0 deletions CombineCoreBluetooth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_UPCOMING_FEATURE_GLOBAL_CONCURRENCY = YES;
SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION = YES;
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -502,6 +504,8 @@
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_UPCOMING_FEATURE_GLOBAL_CONCURRENCY = YES;
SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION = YES;
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"revision" : "ea631ce892687f5432a833312292b80db238186a",
"version" : "1.0.0"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"version" : "1.0.0"
}
}
],
"version" : 2
Expand Down
40 changes: 20 additions & 20 deletions Tests/CombineCoreBluetoothTests/PeripheralTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,43 +263,43 @@ extension Publisher {
} receiveValue: { output in
value = output
}

_ = XCTWaiter.wait(for: [exp], timeout: 1)
sub.cancel()

if let error = error {
throw error
} else {
return value
}
}

func firstValue() async throws -> Output? {
try await values.first(where: { _ in true })
}


func neverComplete() -> AnyPublisher<Output, Failure> {
append(Empty(completeImmediately: false))
.eraseToAnyPublisher()
}
}
}

private var values: AsyncThrowingStream<Output, Error> {
AsyncThrowingStream { continuation in
let cancellable: AnyCancellable = sink(
extension Publisher where Output: Sendable {
func firstValue() async throws -> Output {
try await withCheckedThrowingContinuation { c in
var cancellation: AnyCancellable?
cancellation = self.first().sink(
receiveCompletion: { completion in
switch completion {
case .finished:
continuation.finish()
case .failure(let error):
continuation.finish(throwing: error)
if case let .failure(error) = completion {
c.resume(throwing: error)
cancellation = nil
} else {
if cancellation != nil {
c.resume(throwing: CancellationError())
}
cancellation = nil
}
}, receiveValue: { value in
continuation.yield(value)
c.resume(returning: value)
cancellation = nil
}
)
continuation.onTermination = { @Sendable _ in
cancellable.cancel()
}
}
}
}
Expand Down