Skip to content

Commit

Permalink
Merge pull request #15 Add CreateAsync method and IDisposeAsync inter…
Browse files Browse the repository at this point in the history
…face implementation
  • Loading branch information
rekby authored Aug 10, 2023
2 parents b486600 + 4c6154d commit 7980f65
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Ydb.Sdk/src/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Ydb.Sdk
{
public class Driver : IDisposable
public class Driver : IDisposable, IAsyncDisposable
{
private readonly DriverConfig _config;
private readonly ILoggerFactory _loggerFactory;
Expand All @@ -35,6 +35,13 @@ public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null)
_sdkInfo = $"ydb-dotnet-sdk/{versionStr}";
}

public static async Task<Driver> CreateInitialized(DriverConfig config, ILoggerFactory? loggerFactory = null)
{
var driver = new Driver(config, loggerFactory);
await driver.Initialize();
return driver;
}

public ILoggerFactory LoggerFactory
{
get { return _loggerFactory; }
Expand All @@ -43,6 +50,7 @@ public ILoggerFactory LoggerFactory
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

void Dispose(bool disposing)
Expand All @@ -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");
Expand Down

0 comments on commit 7980f65

Please sign in to comment.