In the asynchronous method, where the code is awaitnothing, is there a reason that someone will mark it async, wait for the task, and then return?
Besides the potential need for it, what are the negative consequences of this?
In this example, suppose it QueryAsync<int>returns Task<int>.
private static async Task<int> InsertRecord_AsyncKeyword(SqlConnection openConnection)
{
int autoIncrementedReferralId =
await openConnection.QueryAsync<int>(@"
INSERT INTO...
SELECT CAST(SCOPE_IDENTITY() AS int)"
);
return autoIncrementedReferralId;
}
private static Task<int> InsertRecord_NoAsyncKeyword(SqlConnection openConnection)
{
Task<int> task =
openConnection.QueryAsync<int>(@"
INSERT INTO...
SELECT CAST(SCOPE_IDENTITY() AS int)"
);
return task;
}
using (SqlConnection connection = await DbConnectionFactory.GetOpenConsumerAppSqlConnectionAsync())
{
int result1 = await InsertRecord_NoAsyncKeyword(connection);
int result2 = await InsertRecord_AsyncKeyword(connection);
}
source
share