Skip to content

Commit

Permalink
Query: Use cancellationToken appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel committed Sep 8, 2021
1 parent f96aa98 commit b3eb4f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 20 additions & 6 deletions src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ public override bool NextResult()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Task<bool> NextResultAsync(CancellationToken cancellationToken)
=> Task.FromResult(NextResult());
{
cancellationToken.ThrowIfCancellationRequested();

return Task.FromResult(NextResult());
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -884,16 +888,26 @@ public bool IsDBNull(int ordinal)
public bool Read()
=> IsDataReady = ++_currentRowNumber < _rowCount;

#pragma warning disable IDE0060 // Remove unused parameter
public Task<T> GetFieldValueAsync<T>(int ordinal, CancellationToken cancellationToken)
=> Task.FromResult(GetFieldValue<T>(ordinal));
{
cancellationToken.ThrowIfCancellationRequested();

return Task.FromResult(GetFieldValue<T>(ordinal));
}

public Task<bool> IsDBNullAsync(int ordinal, CancellationToken cancellationToken)
=> Task.FromResult(IsDBNull(ordinal));
{
cancellationToken.ThrowIfCancellationRequested();

return Task.FromResult(IsDBNull(ordinal));
}

public Task<bool> ReadAsync(CancellationToken cancellationToken)
=> Task.FromResult(Read());
#pragma warning restore IDE0060 // Remove unused parameter
{
cancellationToken.ThrowIfCancellationRequested();

return Task.FromResult(Read());
}

public BufferedDataRecord Initialize(DbDataReader reader, IReadOnlyList<ReaderColumn> columns)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,10 +1482,11 @@ private static async Task PopulateSplitIncludeCollectionAsync<TIncludingEntity,
(queryContext, relationalCommandCache, detailedErrorsEnabled),
((RelationalQueryContext, RelationalCommandCache, bool) tup, CancellationToken cancellationToken)
=> InitializeReaderAsync(tup.Item1, tup.Item2, tup.Item3, cancellationToken),
verifySucceeded: null)
verifySucceeded: null,
queryContext.CancellationToken)
.ConfigureAwait(false);

async Task<RelationalDataReader> InitializeReaderAsync(
static async Task<RelationalDataReader> InitializeReaderAsync(
RelationalQueryContext queryContext,
RelationalCommandCache relationalCommandCache,
bool detailedErrorsEnabled,
Expand Down Expand Up @@ -1801,10 +1802,11 @@ private static async Task PopulateSplitCollectionAsync<TCollection, TElement, TR
(queryContext, relationalCommandCache, detailedErrorsEnabled),
((RelationalQueryContext, RelationalCommandCache, bool) tup, CancellationToken cancellationToken)
=> InitializeReaderAsync(tup.Item1, tup.Item2, tup.Item3, cancellationToken),
verifySucceeded: null)
verifySucceeded: null,
queryContext.CancellationToken)
.ConfigureAwait(false);

async Task<RelationalDataReader> InitializeReaderAsync(
static async Task<RelationalDataReader> InitializeReaderAsync(
RelationalQueryContext queryContext,
RelationalCommandCache relationalCommandCache,
bool detailedErrorsEnabled,
Expand Down

0 comments on commit b3eb4f6

Please sign in to comment.