Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CreateAsync method and IDisposeAsync interface implementation #15

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading