neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.01k stars 895 forks source link

`CancellableDisposable` does not call `_cts.Dispose()` #524

Closed HamzaRino closed 1 year ago

HamzaRino commented 1 year ago

We are using UniRx and UniTask. I want to use CancellableDisposable as I usually need to Cancel on Disposal. I started to use UniRx.CancellableDisposable only to find out its implementation does not actually Dispose the inner CancellationTokenSource. And this is the same thing in original implementation System.Reactive.Disposables.CancellableDisposable.

Is this OK? expected? Should I stop using CancellableDisposable and use our own implementation:

private class DisposableCancellation : IDisposable
{
            private CancellationTokenSource _cts;

            public DisposableCancellation(CancellationTokenSource cts)
            {
                _cts = cts;
            }

            void IDisposable.Dispose()
            {
                _cts.Cancel();
                _cts.Dispose();
                _cts = null;
            }
}
HamzaRino commented 1 year ago

closed as answered here.