瀏覽代碼

async suspendDelivery func

polscm32 1 年之前
父節點
當前提交
7918231e97
共有 1 個文件被更改,包括 16 次插入6 次删除
  1. 16 6
      FreeAPS/Sources/APS/APSManager.swift

+ 16 - 6
FreeAPS/Sources/APS/APSManager.swift

@@ -1408,20 +1408,30 @@ private extension PumpManager {
         }
     }
 
-    func suspendDelivery() -> AnyPublisher<Void, Error> {
-        Future { promise in
+    func suspendDelivery() async throws {
+        try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
             self.suspendDelivery { error in
                 if let error = error {
-                    promise(.failure(error))
+                    continuation.resume(throwing: error)
                 } else {
-                    promise(.success(()))
+                    continuation.resume()
                 }
             }
         }
-        .mapError { APSError.pumpError($0) }
-        .eraseToAnyPublisher()
     }
 
+//    func resumeDelivery() async throws {
+//        try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
+//            self.resumeDelivery { error in
+//                if let error = error {
+//                    continuation.resume(throwing: error)
+//                } else {
+//                    continuation.resume()
+//                }
+//            }
+//        }
+//    }
+
     func resumeDelivery() -> AnyPublisher<Void, Error> {
         Future { promise in
             self.resumeDelivery { error in