public async ValueTask <bool> MoveNextAsync() { if (_done) { var ex = ExceptionHelper.Terminate(ref _error); if (ex != null) { throw ex; } return(false); } for (; ;) { var success = _queue.TryDequeue(out var entry); if (success) { var b = _buffer; if (entry.Done) { _done = true; if (b != null) { Current = b; _buffer = default; return(true); } var ex = ExceptionHelper.Terminate(ref _error); if (ex != null) { throw ex; } return(false); } if (entry.Boundary) { if (b == null) { Current = _collectionSupplier(); } else { Current = b; _buffer = default; } _size = 0; MoveNextOther(); return(true); } if (b == null) { b = _collectionSupplier(); _buffer = b; } b.Add(entry.Value); if (++_size == _maxSize) { Current = b; _buffer = default; _size = 0; MoveNextSource(); return(true); } MoveNextSource(); continue; } await ResumeHelper.Await(ref _resume); ResumeHelper.Clear(ref _resume); } }