public IAsyncEnumerator <int> GetAsyncEnumerator(CancellationToken cancellationToken = default) { CountAsyncEnumerable cae = Interlocked.CompareExchange(ref _state, StateStart, StateCtor) == StateCtor ? this : new CountAsyncEnumerable(_param_items) { _state = StateStart }; cae._cancellationToken = cancellationToken; return(cae); }
public ValueTask <bool> MoveNextAsync() { _vts.Reset(); CountAsyncEnumerable inst = this; _builder.MoveNext(ref inst); // invokes MoveNext, protected by ExecutionContext guards switch (_vts.GetStatus(_vts.Version)) { case ValueTaskSourceStatus.Succeeded: return(new ValueTask <bool>(_vts.GetResult(_vts.Version))); default: return(new ValueTask <bool>(this, _vts.Version)); } }