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; } }
public void Dispose() { try { m_iterator.Dispose(); } finally { m_transaction.Dispose(); } }
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(); } } } }