sideeffect-io / AsyncExtensions

AsyncExtensions aims to mimic Swift Combine operators for async sequences.
MIT License
334 stars 26 forks source link

multicast: dont cancel upstream sequence when client is cancelled #32

Closed twittemb closed 1 year ago

twittemb commented 1 year ago

Description

This PR makes the multicast operator iterate over the upstream sequence in a dedicated task so that collaborative cancellation does not apply. In a multicast world, the upstream sequence should continue to be iterated by new Tasks when one of its client is cancelled.

Checklist

Kolos65 commented 1 year ago

Hey there @twittemb 🙋‍♂️

So then how do you cancel the upstream sequence or how will it be canceled? This leads to upstream sequences being stuck in the global scoped Task of the multicast sequence.

If you use share() for example to improve performance by not producing the same values of an expensive async sequence, the upstream sequence will never be cancelled properly after all clients are cancelled.

Kolos65 commented 1 year ago

I think upstream sequences should be cancelled somehow if there are no clients and the only reference to them is the capture of the multicast sequence's Task.