Questions tagged [anycancellable]

4 questions
56
votes
5 answers

iOS Swift Combine: cancel a Set

If I have stored a cancellable set into a ViewController: private var bag = Set() Which contains multiple subscription. 1 - Should I cancel subscription in deinit? or it does the job automatically? 2 - If so, how can I cancel all…
Andrea Miotto
  • 7,084
  • 8
  • 45
  • 70
1
vote
1 answer

How do I handle cancelling of publishers in Combine's Future functions?

In RxSwift you can create a reactive function something like this: func aFunc() -> Observable { return Observable.create({ emitter in let disposable = Observable .combineLatest(someObservable, …
Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18
1
vote
2 answers

Swift Combine Cancel Publishers Without AnyCancellable

I have my networking library based on Combine. Anywhere in my app I can make a request and the networking library returns a publisher, it doesn't have access to the AnyCancellable that is created that actually triggers the pipeline. What I need is…
Kevin
  • 483
  • 3
  • 11
0
votes
1 answer

Nil'ing AnyCancellable not cancelling subscription

From the documentation An AnyCancellable instance automatically calls cancel() when deinitialized. Yet in the following code var cancellable: AnyCancellable? let subject: PassthroughSubject? = PassthroughSubject() …
Yogurt
  • 2,913
  • 2
  • 32
  • 63