CurrentValueSubject: ignore the first value on subscribe and trigger update only if there is already a value

35 Views Asked by At

Code:

private var _nwPathStatusSubject: CurrentValueSubject<NWPath.Status, Never> = .init(.satisfied)
private var networkPathStatusPublisher: AnyPublisher<NWPath.Status, Never> {
    _nwPathStatusSubject
        .removeDuplicates()
        .eraseToAnyPublisher()
}

    networkStatusCancellable = networkPathStatusPublisher
        .sink {[weak self] newStatus in
            print(newStatus)
        }

The moment I subscribe to the networkPathStatusPublisher I get notified in the .sink {[weak self] newStatus in

I'd like to ignore the current/first value on subscription and only make the further event to trigger the execution of the sink.

0

There are 0 best solutions below