예제 #1
0
        public async ValueTask <bool> RemoveSubscription()
        {
            if (_disposed == 1)
            {
                throw new ObjectDisposedException(nameof(EventSubscriptionBase));
            }

            // accepted race condition, _busy can be disposed here and will throw an ObjectDisposedException

            await _busy.WaitAsync().CfAwait();

            try
            {
                if (_subscriptionsCount == 0)
                {
                    return(true);                          // TODO: should we throw?
                }
                if (_subscriptionsCount > 1)
                {
                    return(true);
                }

                var removed = await ClusterEvents.RemoveSubscriptionAsync(_subscriptionId).CfAwait();

                if (removed)
                {
                    _subscriptionsCount--;
                }
                return(removed);
            }
            finally
            {
                _busy.Release();
            }
        }
예제 #2
0
        public async ValueTask DisposeAsync()
        {
            if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 1)
            {
                return;
            }

            await _busy.WaitAsync().CfAwait();

            try
            {
                if (_subscriptionsCount == 0)
                {
                    return;
                }

                // remove, ignore result
                await ClusterEvents.RemoveSubscriptionAsync(_subscriptionId).CfAwait();
            }
            finally
            {
                _busy.Release();
            }

            _busy.Dispose();

            // this should not be a warning
            // https://github.com/dotnet/roslyn-analyzers/issues/3909
            // https://github.com/dotnet/roslyn-analyzers/issues/3675
            // https://github.com/dotnet/roslyn-analyzers/pull/3679
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
            GC.SuppressFinalize(this);
#pragma warning restore CA1816
        }