Skip to content

Commit e0c899c

Browse files
committed
Use async iterators in IgnoreElements.
1 parent ca0a8b5 commit e0c899c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/IgnoreElements.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@ public static IAsyncEnumerable<TSource> IgnoreElements<TSource>(this IAsyncEnume
1616
if (source == null)
1717
throw Error.ArgumentNull(nameof(source));
1818

19+
#if USE_ASYNC_ITERATOR
20+
return Create(Core);
21+
22+
async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
23+
{
24+
await foreach (var _ in source.WithCancellation(cancellationToken).ConfigureAwait(false))
25+
{
26+
}
27+
}
28+
#else
1929
return new IgnoreElementsAsyncIterator<TSource>(source);
30+
#endif
2031
}
2132

33+
#if !USE_ASYNC_ITERATOR
2234
private sealed class IgnoreElementsAsyncIterator<TSource> : AsyncIterator<TSource>
2335
{
2436
private readonly IAsyncEnumerable<TSource> _source;
@@ -69,4 +81,5 @@ protected override async ValueTask<bool> MoveNextCore()
6981
}
7082
}
7183
}
84+
#endif
7285
}

0 commit comments

Comments
 (0)