Skip to content

Commit 72c676b

Browse files
committed
PrefetchQuery: Implement IAsyncEnumerable to not require extra operation
- AsAsyncEnumerable() marked as Obsolete
1 parent ea0f284 commit 72c676b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Orm/Xtensive.Orm/Orm/PrefetchQuery.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Xtensive.Orm
1919
/// initial query result.
2020
/// </summary>
2121
/// <typeparam name="TElement">The type of the queried elements.</typeparam>
22-
public readonly struct PrefetchQuery<TElement> : IEnumerable<TElement>
22+
public readonly struct PrefetchQuery<TElement> : IEnumerable<TElement>, IAsyncEnumerable<TElement>
2323
{
2424
private readonly Session session;
2525
private readonly IEnumerable<TElement> source;
@@ -38,9 +38,14 @@ internal PrefetchQuery<TElement> RegisterPath<TValue>(Expression<Func<TElement,
3838
public IEnumerator<TElement> GetEnumerator() =>
3939
new PrefetchQueryEnumerable<TElement>(session, source, nodes).GetEnumerator();
4040

41+
/// <inheritdoc />
42+
public IAsyncEnumerator<TElement> GetAsyncEnumerator(CancellationToken token = default) =>
43+
new PrefetchQueryAsyncEnumerable<TElement>(session, source, nodes).GetAsyncEnumerator(token);
44+
4145
/// <summary>
4246
/// Transforms <see cref="PrefetchQuery{TElement}"/> to an <see cref="IAsyncEnumerable{T}"/> sequence.
4347
/// </summary>
48+
[Obsolete("PrefetchQuery itself is an IAsyncEnumerable implementation")]
4449
public IAsyncEnumerable<TElement> AsAsyncEnumerable() =>
4550
new PrefetchQueryAsyncEnumerable<TElement>(session, source, nodes);
4651

@@ -68,8 +73,7 @@ public ExecuteAsyncResult(List<TElement> items, StrongReferenceContainer referen
6873
/// <para>
6974
/// This method internally puts all elements of the resulting sequence to a list
7075
/// and then it wraps mentioned list as a <see cref="QueryResult{TItem}"/>.
71-
/// As a consequence it is more efficient to use asynchronous enumeration over result of
72-
/// <see cref="AsAsyncEnumerable"/> method call because it can perform lazily
76+
/// As a consequence it is more efficient to use asynchronous enumeration because it can perform lazily
7377
/// not putting everything into intermediate list.
7478
/// </para>
7579
/// <para> Multiple active operations are not supported. Use <see langword="await"/>

0 commit comments

Comments
 (0)