Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<int> Xs()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,12 +38,13 @@ public static IAsyncEnumerable<TSource> SkipLast<TSource>(this IAsyncEnumerable<
return source;
}

count = 0;
return source.Wrap();
}

return Core(source, count);

static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, int count, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, int count,
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var queue = new Queue<TSource>();

Expand All @@ -57,8 +58,8 @@ static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, in
{
yield return queue.Dequeue();
queue.Enqueue(e.Current);
}
while (await e.MoveNextAsync());
} while (await e.MoveNextAsync());

break;
}
else
Expand Down
14 changes: 14 additions & 0 deletions Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Wrap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace System.Linq
{
public static partial class AsyncEnumerable
{
internal static async IAsyncEnumerable<TSource> Wrap<TSource>(this IAsyncEnumerable<TSource> source)
{
await foreach (var e in source.ConfigureAwait(false))
yield return e;
}
}
}