Skip to content

Commit

Permalink
Fix pairing session check
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jun 22, 2024
1 parent 4aa2d0a commit 6ca3147
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/SpeziDevices/Devices/PairableDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension PairableDevice {
}


try await pairing.pairingSession {
try await pairing.withPairingSession {
await connect()

async let _ = withTimeout(of: .seconds(15)) {
Expand Down
11 changes: 6 additions & 5 deletions Sources/SpeziDevices/Model/PairingContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class PairingContinuation {
/// Create a new pairing continuation management object.
public init() {}

func pairingSession<T>(_ action: () async throws -> T) async throws -> T {
func withPairingSession<T>(_ action: () async throws -> T) async throws -> T {
try lock.withLock {
guard !isInSession else {
throw DevicePairingError.busy
Expand All @@ -40,11 +40,12 @@ public final class PairingContinuation {
}

func assign(continuation: CheckedContinuation<Void, Error>) {
if lock.try() {
lock.unlock()
preconditionFailure("Tried to assign continuation outside of calling pairingSession(_:)")
lock.withLock {
guard isInSession else {
preconditionFailure("Tried to assign continuation outside of calling withPairingSession(_:)")
}
self.pairingContinuation = continuation
}
self.pairingContinuation = continuation
}

private func resumePairingContinuation(with result: Result<Void, Error>) {
Expand Down

0 comments on commit 6ca3147

Please sign in to comment.