TM-SGNL-iOS/SignalServiceKit/PromiseKit/NotificationCenter+Promise.swift
TeleMessage developers dde0620daf initial commit
2025-05-03 12:28:28 -07:00

17 lines
552 B
Swift

//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
public extension NotificationCenter {
func observe(once name: Notification.Name, object: Any? = nil) -> Guarantee<Notification> {
let (guarantee, future) = Guarantee<Notification>.pending()
let observer = addObserver(forName: name, object: object, queue: nil) { notification in
future.resolve(notification)
}
guarantee.done { _ in self.removeObserver(observer) }
return guarantee
}
}