Skip to content

Commit f277b7c

Browse files
author
Oren Ferrari
committed
Fix to avoid strange async logic behavior.
1 parent 9ece00f commit f277b7c

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

Extensions.Retrieve.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,25 @@ static async Task<QueryResult<Queue<object[]>>> RetrieveAsyncInternal(DbDataRead
184184

185185
var t = token ?? CancellationToken.None;
186186
var buffer = new Queue<object[]>();
187-
if (readStarted || useReadAsync ? await reader.ReadAsync(t) : (!t.IsCancellationRequested && reader.Read()))
188-
{
189-
do
190-
{
191-
buffer.Enqueue(handler(reader));
192-
}
193-
while (useReadAsync ? await reader.ReadAsync(t) : (!t.IsCancellationRequested && reader.Read()));
194-
}
195187

196-
if (!useReadAsync) t.ThrowIfCancellationRequested();
188+
if (!readStarted)
189+
readStarted = useReadAsync
190+
? await reader.ReadAsync(t)
191+
: (!t.IsCancellationRequested && reader.Read());
192+
193+
if (readStarted)
194+
{
195+
do
196+
{
197+
buffer.Enqueue(handler(reader));
198+
}
199+
while (useReadAsync
200+
? await reader.ReadAsync(t)
201+
: (!t.IsCancellationRequested && reader.Read()));
202+
}
203+
204+
if (!useReadAsync)
205+
t.ThrowIfCancellationRequested();
197206

198207
return new QueryResult<Queue<object[]>>(
199208
ordinals,

0 commit comments

Comments
 (0)