From 04e7a526ad25d66978387c83a871a631699d48c0 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Wed, 9 Aug 2023 13:53:41 +0300 Subject: [PATCH 1/2] added CreateAsync method and IDisposeAsync interface implementation --- src/Ydb.Sdk/src/Driver.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Ydb.Sdk/src/Driver.cs b/src/Ydb.Sdk/src/Driver.cs index 589278af..1770591a 100644 --- a/src/Ydb.Sdk/src/Driver.cs +++ b/src/Ydb.Sdk/src/Driver.cs @@ -11,7 +11,7 @@ namespace Ydb.Sdk { - public class Driver : IDisposable + public class Driver : IDisposable, IAsyncDisposable { private readonly DriverConfig _config; private readonly ILoggerFactory _loggerFactory; @@ -35,6 +35,13 @@ public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null) _sdkInfo = $"ydb-dotnet-sdk/{versionStr}"; } + public static async Task CreateAsync(DriverConfig config, ILoggerFactory? loggerFactory = null) + { + var driver = new Driver(config, loggerFactory); + await driver.Initialize(); + return driver; + } + public ILoggerFactory LoggerFactory { get { return _loggerFactory; } @@ -43,6 +50,7 @@ public ILoggerFactory LoggerFactory public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } void Dispose(bool disposing) @@ -63,6 +71,13 @@ void Dispose(bool disposing) } } + public ValueTask DisposeAsync() + { + Dispose(true); + GC.SuppressFinalize(this); + return default; + } + public async Task Initialize() { _logger.LogInformation("Started initial endpoint discovery"); From 4c6154d47154a8490cf695cbd869ca060b9e8986 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Wed, 9 Aug 2023 15:15:44 +0300 Subject: [PATCH 2/2] change method name CreateAsync -> CreateInitialized --- src/Ydb.Sdk/src/Driver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ydb.Sdk/src/Driver.cs b/src/Ydb.Sdk/src/Driver.cs index 1770591a..a040666d 100644 --- a/src/Ydb.Sdk/src/Driver.cs +++ b/src/Ydb.Sdk/src/Driver.cs @@ -35,7 +35,7 @@ public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null) _sdkInfo = $"ydb-dotnet-sdk/{versionStr}"; } - public static async Task CreateAsync(DriverConfig config, ILoggerFactory? loggerFactory = null) + public static async Task CreateInitialized(DriverConfig config, ILoggerFactory? loggerFactory = null) { var driver = new Driver(config, loggerFactory); await driver.Initialize();