Skip to content

Commit

Permalink
Merge pull request #38 from StarryInternet/fix-warnings
Browse files Browse the repository at this point in the history
Fix concurrency warnings in tests
  • Loading branch information
klundberg authored Oct 31, 2024
2 parents f5855b8 + b09bbe6 commit 17ef837
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
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

0 comments on commit 17ef837

Please sign in to comment.