Skip to content

Commit 643e975

Browse files
committed
Removing exception converter from state-less continue task helper
1 parent 8e5a724 commit 643e975

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.NonQuery.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ private void RunExecuteNonQueryTdsSetupReconnnectContinuation(
886886
timeoutCts.Token);
887887

888888
AsyncHelper.ContinueTask(
889-
reconnectTask,
890-
completion,
889+
taskToContinue: reconnectTask,
890+
taskCompletionSource: completion,
891891
onSuccess: () =>
892892
{
893893
if (completion.Task.IsCompleted)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,10 +1634,9 @@ private void RunExecuteReaderTdsSetupReconnectContinuation(
16341634
onTimeout: static () => SQL.CR_ReconnectTimeout(),
16351635
timeoutCts.Token);
16361636

1637-
// @TODO: With an object to pass around we can use the state-based version
16381637
AsyncHelper.ContinueTask(
1639-
reconnectTask,
1640-
completion,
1638+
taskToContinue: reconnectTask,
1639+
taskCompletionSource: completion,
16411640
onSuccess: () =>
16421641
{
16431642
if (completion.Task.IsCompleted)
@@ -1669,7 +1668,7 @@ private void RunExecuteReaderTdsSetupReconnectContinuation(
16691668
taskToContinue: subTask,
16701669
taskCompletionSource: completion,
16711670
state: completion,
1672-
onSuccess: static state => state.SetResult(null));
1671+
onSuccess: static completion2 => completion2.SetResult(null));
16731672
}
16741673
});
16751674
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10761,11 +10761,23 @@ private Task TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParamet
1076110761
}
1076210762

1076310763
// This is in its own method to avoid always allocating the lambda in TDSExecuteRPCParameter
10764-
private void TDSExecuteRPCParameterSetupWriteCompletion(SqlCommand cmd, IList<_SqlRPC> rpcArray, int timeout, bool inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, bool isCommandProc, bool sync, TaskCompletionSource<object> completion, int startRpc, int startParam, Task writeParamTask)
10764+
private void TDSExecuteRPCParameterSetupWriteCompletion(
10765+
SqlCommand cmd,
10766+
IList<_SqlRPC> rpcArray,
10767+
int timeout,
10768+
bool inSchema,
10769+
SqlNotificationRequest notificationRequest,
10770+
TdsParserStateObject stateObj,
10771+
bool isCommandProc,
10772+
bool sync,
10773+
TaskCompletionSource<object> completion,
10774+
int startRpc,
10775+
int startParam,
10776+
Task writeParamTask)
1076510777
{
1076610778
AsyncHelper.ContinueTask(
10767-
writeParamTask,
10768-
completion,
10779+
taskToContinue: writeParamTask,
10780+
taskCompletionSource: completion,
1076910781
onSuccess: () => TdsExecuteRPC(
1077010782
cmd,
1077110783
rpcArray,
@@ -10777,8 +10789,7 @@ private void TDSExecuteRPCParameterSetupWriteCompletion(SqlCommand cmd, IList<_S
1077710789
sync,
1077810790
completion,
1077910791
startRpc,
10780-
startParam
10781-
),
10792+
startParam),
1078210793
onFailure: exc => TdsExecuteRPC_OnFailure(exc, stateObj));
1078310794
}
1078410795

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4353,9 +4353,16 @@ private Task WriteBytes(ReadOnlySpan<byte> b, int len, int offsetBuffer, bool ca
43534353
// This is in its own method to avoid always allocating the lambda in WriteBytes
43544354
private void WriteBytesSetupContinuation(byte[] array, int len, TaskCompletionSource<object> completion, int offset, Task packetTask)
43554355
{
4356-
AsyncHelper.ContinueTask(packetTask, completion,
4357-
onSuccess: () => WriteBytes(ReadOnlySpan<byte>.Empty, len: len, offsetBuffer: offset, canAccumulate: false, completion: completion, array)
4358-
);
4356+
AsyncHelper.ContinueTask(
4357+
taskToContinue: packetTask,
4358+
taskCompletionSource: completion,
4359+
onSuccess: () => WriteBytes(
4360+
ReadOnlySpan<byte>.Empty,
4361+
len: len,
4362+
offsetBuffer: offset,
4363+
canAccumulate: false,
4364+
completion: completion,
4365+
array));
43594366
}
43604367

43614368
/// <summary>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Utilities/AsyncHelper.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ internal static void ContinueTask(
1717
TaskCompletionSource<object> taskCompletionSource,
1818
Action onSuccess,
1919
Action<Exception> onFailure = null,
20-
Action onCancellation = null,
21-
Func<Exception, Exception> exceptionConverter = null)
20+
Action onCancellation = null)
2221
{
2322
taskToContinue.ContinueWith(
2423
tsk =>
2524
{
2625
if (tsk.Exception != null)
2726
{
2827
Exception exc = tsk.Exception.InnerException;
29-
if (exceptionConverter != null)
30-
{
31-
exc = exceptionConverter(exc);
32-
}
3328
try
3429
{
3530
onFailure?.Invoke(exc);
@@ -62,8 +57,8 @@ internal static void ContinueTask(
6257
taskCompletionSource.SetException(e);
6358
}
6459
}
65-
}, TaskScheduler.Default
66-
);
60+
},
61+
TaskScheduler.Default);
6762
}
6863

6964
internal static void ContinueTaskWithState<TState>(

0 commit comments

Comments
 (0)