fix: avoid sendable issue in mac location timeout
This commit is contained in:
@@ -11,6 +11,9 @@ final class MacNodeLocationService: NSObject, CLLocationManagerDelegate {
|
|||||||
|
|
||||||
private let manager = CLLocationManager()
|
private let manager = CLLocationManager()
|
||||||
private var locationContinuation: CheckedContinuation<CLLocation, Swift.Error>?
|
private var locationContinuation: CheckedContinuation<CLLocation, Swift.Error>?
|
||||||
|
private struct UncheckedSendable<T>: @unchecked Sendable {
|
||||||
|
let value: T
|
||||||
|
}
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
@@ -68,15 +71,15 @@ final class MacNodeLocationService: NSObject, CLLocationManagerDelegate {
|
|||||||
return try await operation()
|
return try await operation()
|
||||||
}
|
}
|
||||||
|
|
||||||
return try await withThrowingTaskGroup(of: T.self) { group in
|
return try await withThrowingTaskGroup(of: UncheckedSendable<T>.self) { group in
|
||||||
group.addTask { try await operation() }
|
group.addTask { try await UncheckedSendable(value: operation()) }
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await Task.sleep(nanoseconds: UInt64(timeoutMs) * 1_000_000)
|
try await Task.sleep(nanoseconds: UInt64(timeoutMs) * 1_000_000)
|
||||||
throw Error.timeout
|
throw Error.timeout
|
||||||
}
|
}
|
||||||
let result = try await group.next()!
|
let result = try await group.next()!
|
||||||
group.cancelAll()
|
group.cancelAll()
|
||||||
return result
|
return result.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user