public IFdbAsyncEnumerator <TResult> GetEnumerator(FdbAsyncMode mode) { IFdbAsyncEnumerator <TSource> inner = null; try { inner = this.Source.GetEnumerator(mode); Contract.Requires(inner != null, "The underlying async sequence returned an empty enumerator"); var outer = this.Factory(inner); if (outer == null) { throw new InvalidOperationException("The async factory returned en empty enumerator"); } return(outer); } catch (Exception) { //make sure that the inner iterator gets disposed if something went wrong if (inner != null) { inner.Dispose(); } throw; } }
protected override Task <bool> OnFirstAsync(CancellationToken ct) { // on the first call to MoveNext, we have to hook up with the source iterator IFdbAsyncEnumerator <TSource> iterator = null; try { iterator = StartInner(); if (iterator == null) { return(TaskHelpers.FalseTask); } OnStarted(iterator); return(TaskHelpers.TrueTask); } catch (Exception) { // whatever happens, make sure that we released the iterator... if (iterator != null) { iterator.Dispose(); iterator = null; } throw; } finally { m_iterator = iterator; } }
protected override Task <bool> OnFirstAsync(CancellationToken cancellationToken) { // on first call, setup the page iterator if (m_chunkIterator == null) { m_chunkIterator = new PagingIterator(m_query, m_transaction).GetEnumerator(m_mode); } return(TaskHelpers.TrueTask); }
public FdbAsyncIteratorPump( IFdbAsyncEnumerator <TInput> iterator, IAsyncTarget <TInput> target ) { Contract.Requires(iterator != null); Contract.Requires(target != null); m_iterator = iterator; m_target = target; }
protected override void Cleanup() { try { m_chunkIterator?.Dispose(); } finally { m_chunkIterator = null; m_chunk = null; m_outOfChunks = true; m_currentOffsetInChunk = 0; m_itemsRemainingInChunk = 0; } }
internal static IFdbAsyncEnumerator <T> GetEnumerator([NotNull] FdbAsyncSequenceQuery <T> sequence, FdbAsyncMode mode) { var generator = sequence.CompileSequence(sequence.Expression); if (sequence.Transaction != null) { return(generator(sequence.Transaction).GetEnumerator(mode)); } //BUGBUG: how do we get a CancellationToken without a transaction? var ct = CancellationToken.None; IFdbTransaction trans = null; IFdbAsyncEnumerator <T> iterator = null; bool success = true; try { trans = sequence.Database.BeginTransaction(ct); iterator = generator(trans).GetEnumerator(); return(new TransactionIterator(trans, iterator)); } catch (Exception) { success = false; throw; } finally { if (!success) { if (iterator != null) { iterator.Dispose(); } if (trans != null) { trans.Dispose(); } } } }
public TransactionIterator(IFdbTransaction transaction, IFdbAsyncEnumerator <T> iterator) { m_transaction = transaction; m_iterator = iterator; }
protected override void OnStarted(IFdbAsyncEnumerator <TInput> iterator) { // pre-allocate the inner buffer, if it is not too big m_buffer = new List <TInput>(Math.Min(m_batchSize, 1024)); }
protected virtual void OnStarted(IFdbAsyncEnumerator <TSource> iterator) { //override this to add custom starting logic once we know that the inner iterator is ready }
protected override void OnStarted(IFdbAsyncEnumerator <TInput> iterator) { // pre-allocate the buffer with the number of slot we expect to use m_buffer = new Queue <TInput>(m_prefetchCount); }
public OrderedEnumerator(IFdbAsyncEnumerator <TSource> enumerator, SequenceSorter <TSource> sorter) { Contract.Requires(enumerator != null && sorter != null); m_inner = enumerator; m_sorter = sorter; }