CustomNotification.swift 1.0 KB

123456789101112131415161718192021222324252627
  1. import Combine
  2. import Foundation
  3. extension Notification.Name {
  4. static let willUpdateOverrideConfiguration = Notification.Name("willUpdateOverrideConfiguration")
  5. static let didUpdateOverrideConfiguration = Notification.Name("didUpdateOverrideConfiguration")
  6. static let didUpdateTempTargetConfiguration = Notification.Name("didUpdateTempTargetConfiguration")
  7. static let liveActivityOrderDidChange = Notification.Name("liveActivityOrderDidChange")
  8. }
  9. func awaitNotification(_ name: Notification.Name) async {
  10. await withCheckedContinuation { continuation in
  11. var cancellable: AnyCancellable?
  12. // Create a Combine publisher that listens for notifications
  13. cancellable = Foundation.NotificationCenter.default
  14. .publisher(for: name)
  15. .sink { _ in
  16. // When the notification is received, resume the awaiting task
  17. continuation.resume()
  18. // Cancel the subscription after the continuation has resumed
  19. cancellable?.cancel()
  20. }
  21. }
  22. }