public void ConfigureAwait_EnumeratorMembers_Default_Throws()
 {
     ConfiguredAsyncEnumerable <int> .Enumerator e = default;
     Assert.Throws <NullReferenceException>(() => e.MoveNextAsync());
     Assert.Throws <NullReferenceException>(() => e.Current);
     Assert.Throws <NullReferenceException>(() => e.DisposeAsync());
 }
        public void ConfigureAwait_GetAsyncEnumerator_Default_Throws()
        {
            ConfiguredAsyncEnumerable <int> e = default;

            Assert.Throws <NullReferenceException>(() => e.GetAsyncEnumerator());

            e = ((IAsyncEnumerable <int>)null).ConfigureAwait(false);
            Assert.Throws <NullReferenceException>(() => e.GetAsyncEnumerator());
        }
        public void ConfigureAwait_GetAsyncEnumerator_CancellationTokenPassedthrough()
        {
            var enumerable = new TrackFlagsAsyncEnumerable()
            {
                Flags = 0
            };
            var cts = new CancellationTokenSource();

            ConfiguredAsyncEnumerable <int> .Enumerator enumerator = enumerable.ConfigureAwait(false).GetAsyncEnumerator(cts.Token);
            Assert.Equal(cts.Token, enumerable.CancellationToken);
        }
        public void ConfigureAwait_AwaitDisposeAsync_FlagsSetAppropriately(bool continueOnCapturedContext)
        {
            var enumerable = new TrackFlagsAsyncEnumerable()
            {
                Flags = 0
            };

            ConfiguredAsyncEnumerable <int> .Enumerator             enumerator     = enumerable.ConfigureAwait(continueOnCapturedContext).GetAsyncEnumerator();
            ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter disposeAwaiter = enumerator.DisposeAsync().GetAwaiter();
            disposeAwaiter.UnsafeOnCompleted(() => { });
            Assert.Equal(
                continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None,
                enumerable.Flags);
        }
        public async Task ConfigureAwait_CanBeEnumeratedWithStandardPattern()
        {
            IAsyncEnumerable <int> asyncEnumerable = new EnumerableWithDelayToAsyncEnumerable <int>(Enumerable.Range(1, 10), 1);
            int sum = 0;

            ConfiguredAsyncEnumerable <int> .Enumerator e = asyncEnumerable.ConfigureAwait(false).GetAsyncEnumerator();
            try
            {
                while (await e.MoveNextAsync())
                {
                    sum += e.Current;
                }
            }
            finally
            {
                await e.DisposeAsync();
            }

            Assert.Equal(55, sum);
        }
            protected override R TryMoveNext(int state, bool shouldBreak, out bool?hasNext, out int nextState)
            {
                ConfiguredAsyncEnumerable <T> .Enumerator             __enumerator0 = default;
                ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter __awaiter1    = default;
                Exception __ex0 = default;

                switch (state)
                {
                case 0:
                    goto __State0;

                case 1:
                case 2:
                case 3:
                case 4:
                    goto __EnterTry1;

                case 5:
                    __ex0 = this.__ex0;
                    goto __EnterTry2;

                default:
                    throw new NotImplementedException();
                }

__State0:

                __enumerator0 = source.ConfigureAwait(false).GetAsyncEnumerator();

__EnterTry1:

                try
                {
                    ConfiguredAsyncEnumerable <C> .Enumerator __enumerator1 = default;
                    T         outer = default;
                    Exception __ex1 = default;
                    ConfiguredTaskAwaitable.ConfiguredTaskAwaiter __awaiter2 = default;

                    switch (state)
                    {
                    case 0:
                        break;

                    case 1:
                        __enumerator0 = this.__enumerator0;
                        __awaiter1    = this.__awaiter1;
                        goto __State1;

                    case 2:
                    case 3:
                        __enumerator0 = this.__enumerator0;
                        goto __EnterTry11;

                    case 4:
                        __enumerator0 = this.__enumerator0;
                        outer         = this.outer;
                        __ex1         = this.__ex1;
                        __awaiter2    = this.__awaiter2;
                        goto __State4;

                    default:
                        throw new NotImplementedException();
                    }

__BeginLoop1:

                    __awaiter1 = __enumerator0.WaitForNextAsync().GetAwaiter();

                    if (!__awaiter1.IsCompleted)
                    {
                        this.__enumerator0 = __enumerator0;
                        this.__awaiter1    = __awaiter1;
                        nextState          = 1;
                        AwaitOnCompleted(nextState, ref __awaiter1);
                        hasNext = null;
                        return(default);
Beispiel #7
0
            protected override T TryMoveNext(int state, bool shouldBreak, out bool?hasNext, out int nextState)
            {
                ConfiguredAsyncEnumerable <T> .Enumerator             __enumerator = default;
                ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter __awaiter1   = default;
                Exception __ex = default;

                switch (state)
                {
                case 0:
                    goto __State0;

                case 1:
                case 2:
                    goto __EnterTry1;

                case 3:
                    __ex = this.__ex;
                    goto __EnterTry2;

                default:
                    throw new NotImplementedException();
                }

__State0:

                __enumerator = source.ConfigureAwait(false).GetAsyncEnumerator();

__EnterTry1:

                try
                {
                    switch (state)
                    {
                    case 0:
                        break;

                    case 1:
                        __enumerator = this.__enumerator;
                        __awaiter1   = this.__awaiter1;
                        goto __State1;

                    case 2:
                        __enumerator = this.__enumerator;
                        if (shouldBreak)
                        {
                            goto __State2_Break;
                        }
                        else
                        {
                            goto __State2;
                        }

                    default:
                        throw new NotImplementedException();
                    }

__BeginLoop1:

                    __awaiter1 = __enumerator.WaitForNextAsync().GetAwaiter();

                    if (!__awaiter1.IsCompleted)
                    {
                        this.__enumerator = __enumerator;
                        this.__awaiter1   = __awaiter1;
                        nextState         = 1;
                        AwaitOnCompleted(nextState, ref __awaiter1);
                        hasNext = null;
                        return(default);