//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.GameLogic;
///
/// Extensions for .
///
public static class LazyExtensions
{
///
/// Disposes the value of the lazy instance, if it was created, asynchronously.
///
/// The type of the .
/// The lazy instance.
public static async ValueTask DisposeIfCreatedAsync(this Lazy lazy)
where T : IAsyncDisposable
{
if (lazy.IsValueCreated)
{
await lazy.Value.DisposeAsync().ConfigureAwait(false);
}
}
///
/// Disposes the value of the lazy instance, if created.
///
/// The .
/// The lazy instance.
public static void DisposeIfCreated(this Lazy lazy)
where T : IDisposable
{
if (lazy.IsValueCreated)
{
lazy.Value.Dispose();
}
}
}