コード例 #1
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();
                    }
                }
            }
        }
コード例 #2
0
        internal static IAsyncEnumerator <T> GetEnumerator(FdbAsyncSequenceQuery <T> sequence, AsyncIterationHint mode)
        {
            var generator = sequence.CompileSequence(sequence.Expression);

            if (sequence.Transaction != null)
            {
                var source = generator(sequence.Transaction);
                Contract.Assert(source != null);
                return(source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(sequence.Transaction.Cancellation, mode) : source.GetAsyncEnumerator(sequence.Transaction.Cancellation));
            }

            //BUGBUG: how do we get a CancellationToken without a transaction?
            var ct = CancellationToken.None;

            IFdbTransaction?     trans    = null;
            IAsyncEnumerator <T>?iterator = null;
            bool success = true;

            try
            {
#warning Fix async begin transaction!
                trans = sequence.Database !.BeginTransactionAsync(ct).GetAwaiter().GetResult();                //HACKHACK: BUGBUG: async!
                var source = generator(trans);
                Contract.Assert(source != null);
                iterator = source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(ct, mode) : source.GetAsyncEnumerator(ct);

                return(new TransactionIterator(trans, iterator));
            }
            catch (Exception)
            {
                success = false;
                throw;
            }
            finally
            {
                if (!success)
                {
                    //BUGBUG: we have to block on the async disposable :(
                    iterator?.DisposeAsync().GetAwaiter().GetResult();
                    trans?.Dispose();
                }
            }
        }
コード例 #3
0
        internal static IAsyncEnumerator <T> GetEnumerator([NotNull] FdbAsyncSequenceQuery <T> sequence, AsyncIterationHint mode)
        {
            var generator = sequence.CompileSequence(sequence.Expression);

            if (sequence.Transaction != null)
            {
                var source = generator(sequence.Transaction);
                Contract.Assert(source != null);
                return(source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(sequence.Transaction.Cancellation, mode) : source.GetAsyncEnumerator());
            }

            //BUGBUG: how do we get a CancellationToken without a transaction?
            var ct = CancellationToken.None;

            IFdbTransaction      trans    = null;
            IAsyncEnumerator <T> iterator = null;
            bool success = true;

            try
            {
                trans = sequence.Database.BeginTransaction(ct);
                var source = generator(trans);
                Contract.Assert(source != null);
                iterator = source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(ct, mode) : source.GetAsyncEnumerator();

                return(new TransactionIterator(trans, iterator));
            }
            catch (Exception)
            {
                success = false;
                throw;
            }
            finally
            {
                if (!success)
                {
                    iterator?.Dispose();
                    trans?.Dispose();
                }
            }
        }