mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Switch to a custom HomeserverReachability instead of different publishers
This commit is contained in:
@@ -14,9 +14,12 @@ import Combine
|
||||
/// `CurrentValueSubject` is documented as thread-safe but is not formally `Sendable`, hence `@unchecked`.
|
||||
nonisolated struct CurrentValuePublisher<Output, Failure: Error>: Publisher, @unchecked Sendable {
|
||||
private let subject: CurrentValueSubject<Output, Failure>
|
||||
/// Retains the upstream subscription feeding ``subject`` when this publisher is derived via ``map(_:)``.
|
||||
private let cancellable: AnyCancellable?
|
||||
|
||||
init(_ subject: CurrentValueSubject<Output, Failure>) {
|
||||
init(_ subject: CurrentValueSubject<Output, Failure>, cancellable: AnyCancellable? = nil) {
|
||||
self.subject = subject
|
||||
self.cancellable = cancellable
|
||||
}
|
||||
|
||||
init(_ value: Output) {
|
||||
@@ -32,6 +35,14 @@ nonisolated struct CurrentValuePublisher<Output, Failure: Error>: Publisher, @un
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated extension CurrentValuePublisher where Failure == Never {
|
||||
func map<T>(_ transform: @escaping (Output) -> T) -> CurrentValuePublisher<T, Never> {
|
||||
let subject = CurrentValueSubject<T, Never>(transform(value))
|
||||
let cancellable = sink { subject.send(transform($0)) }
|
||||
return .init(subject, cancellable: cancellable)
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated extension CurrentValueSubject {
|
||||
func asCurrentValuePublisher() -> CurrentValuePublisher<Output, Failure> {
|
||||
.init(self)
|
||||
|
||||
Reference in New Issue
Block a user