Sfoglia il codice sorgente

async suspendDelivery func

polscm32 1 anno fa
parent
commit
7918231e97
1 ha cambiato i file con 16 aggiunte e 6 eliminazioni
  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
             self.suspendDelivery { error in
                 if let error = error {
                 if let error = error {
-                    promise(.failure(error))
+                    continuation.resume(throwing: error)
                 } else {
                 } 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> {
     func resumeDelivery() -> AnyPublisher<Void, Error> {
         Future { promise in
         Future { promise in
             self.resumeDelivery { error in
             self.resumeDelivery { error in