In an async method where the code is not awaiting anything, is there a reason why someone would mark it async, await the task, and then return?
Besides the potential un-necessity of it, what are the negative ramifications of doing so?
For this example, please assume that 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;
}
// Top level method
using (SqlConnection connection = await DbConnectionFactory.GetOpenConsumerAppSqlConnectionAsync())
{
int result1 = await InsertRecord_NoAsyncKeyword(connection);
int result2 = await InsertRecord_AsyncKeyword(connection);
}