diff --git a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs index 016e10f24..5e43d1267 100644 --- a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs +++ b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. -// See the LICENSE file in the project root for more information. +// See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; @@ -64,12 +64,14 @@ public async Task SkipLast_Zero() } [Fact] - public void SkipLast_Zero_NoAlias() + public async Task SkipLast_Zero_NoAlias() { var xs = Xs(); var ys = xs.SkipLast(0); Assert.NotSame(xs, ys); + var e = ys.GetAsyncEnumerator(); + await HasNextAsync(e, 1); } private async IAsyncEnumerable Xs() diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs index fab55d968..b2065ae84 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. -// See the LICENSE file in the project root for more information. +// See the LICENSE file in the project root for more information. using System.Collections.Generic; using System.Diagnostics; @@ -38,12 +38,13 @@ public static IAsyncEnumerable SkipLast(this IAsyncEnumerable< return source; } - count = 0; + return source.Wrap(); } return Core(source, count); - static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core(IAsyncEnumerable source, int count, + [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default) { var queue = new Queue(); @@ -57,8 +58,8 @@ static async IAsyncEnumerable Core(IAsyncEnumerable source, in { yield return queue.Dequeue(); queue.Enqueue(e.Current); - } - while (await e.MoveNextAsync()); + } while (await e.MoveNextAsync()); + break; } else diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Wrap.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Wrap.cs new file mode 100644 index 000000000..e82002ead --- /dev/null +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Wrap.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace System.Linq +{ + public static partial class AsyncEnumerable + { + internal static async IAsyncEnumerable Wrap(this IAsyncEnumerable source) + { + await foreach (var e in source.ConfigureAwait(false)) + yield return e; + } + } +}