/// <summary>Run the pump until the inner iterator is done, an error occurs, or the cancellation token is fired</summary>
        public async Task PumpAsync(CancellationToken ct)
        {
            if (m_state != STATE_IDLE)
            {
                if (m_state >= STATE_FAILED)
                {
                    throw new InvalidOperationException("The iterator pump has already completed once");
                }
                else
                {
                    throw new InvalidOperationException("The iterator pump is already running");
                }
            }

            try
            {
                while (!ct.IsCancellationRequested)
                {
                    LogDebug("waiting for next");
                    m_state = STATE_WAITING_FOR_NEXT;
                    if (!(await m_iterator.MoveNextAsync(ct).ConfigureAwait(false)))
                    {
                        LogDebug("completed");
                        m_state = STATE_DONE;
                        m_target.OnCompleted();
                        return;
                    }

                    LogDebug("got item, publishing...");
                    m_state = STATE_PUBLISHING_TO_TARGET;
                    await m_target.OnNextAsync(m_iterator.Current, ct).ConfigureAwait(false);
                }

                // push the cancellation on the queue
                OnError(ExceptionDispatchInfo.Capture(new OperationCanceledException(ct)));
                // and throw!
            }
            catch (Exception e)
            {
                LogDebug("failed... (" + m_state + ") : " + e.Message);
                if (m_state == STATE_FAILED)
                {                 // already signaled the target, just throw
                    throw;
                }

                // push the error on the queue, and eat the error
                OnError(ExceptionDispatchInfo.Capture(e));
            }
            finally
            {
                if (m_state != STATE_FAILED)
                {
                    m_state = STATE_DONE;
                }
                LogDebug("stopped (" + m_state + ")");
            }
        }
 public Task <bool> MoveNextAsync(CancellationToken cancellationToken)
 {
     return(m_iterator.MoveNextAsync(cancellationToken));
 }