Skip to content

Commit

Permalink
using await on types implementing IAsyncDisposable (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirShitrit authored Apr 12, 2024
1 parent 3ebf839 commit 22d88fd
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Proto.Persistence.SqlServer/SqlServerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public SqlServerProvider(
$@"INSERT INTO [{_tableSchema}].[{_tableSnapshots}] (Id, ActorName, SnapshotIndex, SnapshotData) VALUES (@Id, @ActorName, @SnapshotIndex, @SnapshotData)";
}

public Task DeleteEventsAsync(string actorName, long inclusiveToIndex) =>
ExecuteNonQueryAsync(
public async Task DeleteEventsAsync(string actorName, long inclusiveToIndex) =>
await ExecuteNonQueryAsync(
_sqlDeleteEvents,
CreateParameter("ActorName", NVarChar, actorName),
CreateParameter("EventIndex", BigInt, inclusiveToIndex)
);

public Task DeleteSnapshotsAsync(string actorName, long inclusiveToIndex) =>
ExecuteNonQueryAsync(
public async Task DeleteSnapshotsAsync(string actorName, long inclusiveToIndex) =>
await ExecuteNonQueryAsync(
_sqlDeleteSnapshots,
CreateParameter("ActorName", NVarChar, actorName),
CreateParameter("SnapshotIndex", BigInt, inclusiveToIndex)
Expand Down Expand Up @@ -118,9 +118,9 @@ public async Task<long> GetEventsAsync(string actorName, long indexStart, long i
long snapshotIndex = 0;
object snapshotData = null;

using var connection = new SqlConnection(_connectionString);
await using var connection = new SqlConnection(_connectionString);

using var command = new SqlCommand(_sqlReadSnapshot, connection);
await using var command = new SqlCommand(_sqlReadSnapshot, connection);

await connection.OpenAsync().ConfigureAwait(false);

Expand Down Expand Up @@ -152,14 +152,14 @@ await ExecuteNonQueryAsync(
CreateParameter("EventData", NVarChar, JsonConvert.SerializeObject(item.EventData, AllTypeSettings))
).ConfigureAwait(false);

return index++;
return index + 1;
}

public Task PersistSnapshotAsync(string actorName, long index, object snapshot)
public async Task PersistSnapshotAsync(string actorName, long index, object snapshot)
{
var item = new Snapshot(actorName, index, snapshot);

return ExecuteNonQueryAsync(
await ExecuteNonQueryAsync(
_sqlSaveSnapshot,
CreateParameter("Id", NVarChar, item.Id),
CreateParameter("ActorName", NVarChar, item.ActorName),
Expand Down Expand Up @@ -232,13 +232,13 @@ private static SqlParameter CreateParameter(string name, SqlDbType type, object

private async Task ExecuteNonQueryAsync(string sql, params SqlParameter[] parameters)
{
using var connection = new SqlConnection(_connectionString);
await using var connection = new SqlConnection(_connectionString);

using var command = new SqlCommand(sql, connection);
await using var command = new SqlCommand(sql, connection);

await connection.OpenAsync().ConfigureAwait(false);

using var tx = connection.BeginTransaction();
await using var tx = connection.BeginTransaction();

command.Transaction = tx;

Expand Down

0 comments on commit 22d88fd

Please sign in to comment.