-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fixed CancellationTokenSource Issue #47
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,14 +303,16 @@ public Task<T> ExecuteReaderAsync<T>( | |
string storedProc, | ||
int timeoutSecs, | ||
int maxAttemptCount, | ||
CancellationToken token, | ||
int taskCancellationTimeOutInMilliSecs, | ||
IDbDataParameter[] parameters, | ||
Func<SqlDataReader, Task<T>> callback) | ||
{ | ||
return _dbResources.ChooseDb(database).ExecuteAsync(async (connectionStr, _) => | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
Exception error = null; | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
cancellationTokenSource.CancelAfter(taskCancellationTimeOutInMilliSecs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the operation that you want to include in the timer? Only the query execution, or opening the connection as well? If the first then should we initialize this closer to where it's consumed? Or if you want to timeout even if opening the connection takes a long time, then should we pass the token to connection.OpenAsync() as well? |
||
try | ||
{ | ||
using (var connection = _generateConnection(connectionStr)) | ||
|
@@ -332,7 +334,7 @@ public Task<T> ExecuteReaderAsync<T>( | |
CommandTimeout = timeoutSecs | ||
}; | ||
sqlCommand.Parameters.AddRange(parameters); | ||
using (var reader = await sqlCommand.ExecuteReaderAsync(token)) | ||
using (var reader = await sqlCommand.ExecuteReaderAsync(cancellationTokenSource.Token)) | ||
{ | ||
return await callback(reader); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an
IDisposable
, can we wrap it inusing
?