Reputation: 3322
I have a function (which does some network calls like toggling a flag on the server) which returns AnyPublisher<a,b>
func functionWhichReturnsAnyPublisher() -> AnyPublisher<a,b> {
}
In one of the cases, I do not use the output of it.
Is there any alternative without using the sink on it as I am not using any of the output from the call?
If I do not call sink it is not performing the network operation.
functionWhichReturnsAnyPublisher().sink {_ in } receiveValue: { _ in
}.store(in: &subscriptions)
Upvotes: 0
Views: 760
Reputation: 115041
You must attach a subscriber to a publisher, otherwise the publisher will not start.
You can use ignoreOutput
to ignore the output of a publisher.
functionWhichReturnsAnyPublisher().ignoreOutput().store(in: &subscriptions)
You might want to consider still using sink
so that you can handle any errors that result from the publisher.
Upvotes: 3