-
Notifications
You must be signed in to change notification settings - Fork 317
Cleanup | AsyncHelpers Generic State #3705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8383e19
8119c0c
3df7400
6500240
f4eea9f
8450aaa
547af51
847fd25
cb6d1f9
dd48b59
5b29b7f
153b764
3584c99
14fed23
7684fe7
da6ef3c
f8ccc85
45ef372
0e3250f
aabd04f
ba65f50
453197e
db584d7
2340c83
e20f118
76770ef
c7d06b9
2035cf5
bbc9193
3560027
8ae7470
3f5cfa9
10f39c9
e2a1027
6586700
284ba72
b016488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,10 @@ | |
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Data.Common; | ||
| using Microsoft.Data.SqlClient.Utilities; | ||
|
|
||
| #if NETFRAMEWORK | ||
| using System.Security.Permissions; | ||
| using Microsoft.Data.SqlClient.Utilities; | ||
| #endif | ||
|
|
||
| namespace Microsoft.Data.SqlClient | ||
|
|
@@ -308,14 +308,12 @@ private IAsyncResult BeginExecuteReaderInternal( | |
| if (writeTask is not null) | ||
| { | ||
| AsyncHelper.ContinueTaskWithState( | ||
| writeTask, | ||
| localCompletion, | ||
| state: Tuple.Create(this, localCompletion), | ||
| onSuccess: static state => | ||
| { | ||
| var parameters = (Tuple<SqlCommand, TaskCompletionSource<object>>)state; | ||
| parameters.Item1.BeginExecuteReaderInternalReadStage(parameters.Item2); | ||
| }); | ||
| taskToContinue: writeTask, | ||
| taskCompletionSource: localCompletion, | ||
| state1: this, | ||
| state2: localCompletion, | ||
| onSuccess: static (this2, localCompletion2) => | ||
| this2.BeginExecuteReaderInternalReadStage(localCompletion2)); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -1605,21 +1603,19 @@ private Task RunExecuteReaderTdsSetupContinuation( | |
| string optionSettings, | ||
| Task writeTask) | ||
| { | ||
| // @TODO: Why use the state version if we can't make this a static helper? | ||
| return AsyncHelper.CreateContinuationTaskWithState( | ||
| task: writeTask, | ||
| state: _activeConnection, | ||
| onSuccess: state => | ||
| taskToContinue: writeTask, | ||
| state1: this, | ||
| state2: Tuple.Create(ds, runBehavior, optionSettings), | ||
| onSuccess: static (this2, parameters) => | ||
paulmedynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // This will throw if the connection is closed. | ||
| // @TODO: So... can we have something that specifically does that? | ||
| ((SqlConnection)state).GetOpenTdsConnection(); | ||
| CachedAsyncState.SetAsyncReaderState(ds, runBehavior, optionSettings); | ||
| this2._activeConnection.GetOpenTdsConnection(); | ||
| this2.CachedAsyncState.SetAsyncReaderState(parameters.Item1, parameters.Item2, parameters.Item3); | ||
| }, | ||
| onFailure: static (exception, state) => | ||
| { | ||
| ((SqlConnection)state).GetOpenTdsConnection().DecrementAsyncCount(); | ||
| }); | ||
| onFailure: static (this2, _, _) => | ||
benrr101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this2._activeConnection.GetOpenTdsConnection().DecrementAsyncCount()); | ||
paulmedynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // @TODO: This is way too many parameters being shoveled back and forth. We can do better. | ||
|
|
@@ -1640,13 +1636,12 @@ private void RunExecuteReaderTdsSetupReconnectContinuation( | |
| AsyncHelper.SetTimeoutException( | ||
| completion, | ||
| timeout, | ||
| onFailure: static () => SQL.CR_ReconnectTimeout(), | ||
| onTimeout: static () => SQL.CR_ReconnectTimeout(), | ||
benrr101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| timeoutCts.Token); | ||
|
|
||
| // @TODO: With an object to pass around we can use the state-based version | ||
| AsyncHelper.ContinueTask( | ||
| reconnectTask, | ||
| completion, | ||
| taskToContinue: reconnectTask, | ||
| taskCompletionSource: completion, | ||
| onSuccess: () => | ||
| { | ||
| if (completion.Task.IsCompleted) | ||
|
|
@@ -1675,10 +1670,10 @@ private void RunExecuteReaderTdsSetupReconnectContinuation( | |
| else | ||
| { | ||
| AsyncHelper.ContinueTaskWithState( | ||
| subTask, | ||
| completion, | ||
| taskToContinue: subTask, | ||
| taskCompletionSource: completion, | ||
| state: completion, | ||
| onSuccess: static state => ((TaskCompletionSource<object>)state).SetResult(null)); | ||
| onSuccess: static completion2 => completion2.SetResult(null)); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -1711,14 +1706,13 @@ private SqlDataReader RunExecuteReaderTdsWithTransparentParameterEncryption( | |
| // @TODO: This is a prime candidate for proper async-await execution | ||
| TaskCompletionSource<object> completion = new TaskCompletionSource<object>(); | ||
| AsyncHelper.ContinueTaskWithState( | ||
| task: describeParameterEncryptionTask, | ||
| completion: completion, | ||
| taskToContinue: describeParameterEncryptionTask, | ||
| taskCompletionSource: completion, | ||
| state: this, | ||
| onSuccess: state => | ||
| onSuccess: this2 => | ||
| { | ||
| SqlCommand command = (SqlCommand)state; | ||
| command.GenerateEnclavePackage(); | ||
| command.RunExecuteReaderTds( | ||
| this2.GenerateEnclavePackage(); | ||
| this2.RunExecuteReaderTds( | ||
| cmdBehavior, | ||
| runBehavior, | ||
| returnStream, | ||
|
|
@@ -1737,24 +1731,22 @@ private SqlDataReader RunExecuteReaderTdsWithTransparentParameterEncryption( | |
| else | ||
| { | ||
| AsyncHelper.ContinueTaskWithState( | ||
| task: subTask, | ||
| completion: completion, | ||
| taskToContinue: subTask, | ||
| taskCompletionSource: completion, | ||
| state: completion, | ||
| onSuccess: static state => ((TaskCompletionSource<object>)state).SetResult(null)); | ||
| onSuccess: static state => state.SetResult(null)); | ||
| } | ||
| }, | ||
| onFailure: static (exception, state) => | ||
| onFailure: static (this2, exception) => | ||
| { | ||
| ((SqlCommand)state).CachedAsyncState?.ResetAsyncState(); | ||
| this2.CachedAsyncState?.ResetAsyncState(); | ||
| if (exception is not null) | ||
| { | ||
| // @TODO: This doesn't do anything, afaik. | ||
| throw exception; | ||
|
Comment on lines
+1745
to
1746
|
||
| } | ||
| }, | ||
| onCancellation: static state => | ||
| { | ||
| ((SqlCommand)state).CachedAsyncState?.ResetAsyncState(); | ||
| }); | ||
| onCancellation: static this2 => this2.CachedAsyncState?.ResetAsyncState()); | ||
|
|
||
| task = completion.Task; | ||
| return ds; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.