public ValueTask DisposeAsync()
            {
                _current = default;
                _state = AsyncIteratorState.Disposed;

                Dispose();

                return default;
            }
            public async ValueTask<bool> MoveNextAsync()
            {
                if (_state == AsyncIteratorState.Disposed)
                {
                    return false;
                }

                try
                {
                    _cancellationToken.ThrowIfCancellationRequested();

                    if (_state == AsyncIteratorState.Allocated)
                    {
                        _subscription = _observable.Subscribe(this);
                        _state = AsyncIteratorState.Iterating;
                    }

                    if (_state == AsyncIteratorState.Iterating)
                    {
                        while (true)
                        {
                            await _enumerationSemaphore.WaitAsync(_cancellationToken).ConfigureAwait(false);

                            var completed = Volatile.Read(ref _completed);

                            if (_values.TryDequeue(out _current))
                            {
                                return true;
                            }

                            if (!completed)
                            {
                                continue;
                            }

                            if (_exception != null)
                            {
                                throw _exception;
                            }

                            return false;
                        }
                    }

                    await DisposeAsync().ConfigureAwait(false);
                    return false;
                }
                catch
                {
                    await DisposeAsync().ConfigureAwait(false);
                    throw;
                }
            }
Exemple #3
0
            public virtual void Dispose()
            {
                if (cancellationTokenSource != null)
                {
                    if (!cancellationTokenSource.IsCancellationRequested)
                    {
                        cancellationTokenSource.Cancel();
                    }
                    cancellationTokenSource.Dispose();
                }

                current = default;
                state   = AsyncIteratorState.Disposed;
            }
Exemple #4
0
        public virtual ValueTask DisposeAsync()
        {
            _state = AsyncIteratorState.Disposed;

            return(default);
Exemple #5
0
 public virtual void Dispose()
 {
     _state   = AsyncIteratorState.Disposed;
     _current = default;
 }