CombineCommunity / CombineExt

CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
https://combine.community
MIT License
1.72k stars 151 forks source link

Amb: forward cancel to the inner publishers #144

Open melle opened 2 years ago

melle commented 2 years ago

We noticed that cancelling an Amb publisher does not cancel any of the inner publishers. It looks like nil-ing firstSink / secondSink should do the job, but it does not work. Adding explicit cancel fixes the issue, but I’m not sure if this is the right solution.

luizmb commented 2 years ago

Moving discussion from Twitter. Why Sink.deinit is not calling cancelUpstream automatically (https://github.com/CombineCommunity/CombineExt/blob/main/Sources/Common/Sink.swift#L113)?

Maybe it has a reference cycle and deinit is actually not called?

melle commented 2 years ago

I looked into it: Sink's deinit is not called. That explains why the subscriptions are not cancelled. However, I could not find any explanation for the reference being kept alive. I added the cancel to the decision code as well including another test.

The explicit cancel fixes our problem, but shadows the underlying reference cycle problem. Both tests should pass, when the cancel() calls are removed and the reference cycle has been fixed.