Skip to content

feature/monad-result-disposable #69

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

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions OnixLabs.Core/OnixLabs.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<Title>OnixLabs.Core</Title>
<Authors>ONIXLabs</Authors>
<Description>ONIXLabs Core API for .NET</Description>
<AssemblyVersion>8.11.0</AssemblyVersion>
<AssemblyVersion>8.12.0</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright © ONIXLabs 2020</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<PackageVersion>8.11.0</PackageVersion>
<PackageVersion>8.12.0</PackageVersion>
</PropertyGroup>
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand Down
19 changes: 19 additions & 0 deletions OnixLabs.Core/Result.Failure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System;
using System.Threading.Tasks;

namespace OnixLabs.Core;

Expand Down Expand Up @@ -288,4 +289,22 @@ public sealed class Failure<T> : Result<T>, IValueEquatable<Failure<T>>
/// </summary>
/// <returns>Returns a <see cref="String"/> that represents the current object.</returns>
public override string ToString() => Exception.ToString();

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public override void Dispose()
{
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
/// </summary>
/// <returns>
/// Returns a task that represents the asynchronous dispose operation.
/// </returns>
public override async ValueTask DisposeAsync()
{
await ValueTask.CompletedTask;
}
}
22 changes: 22 additions & 0 deletions OnixLabs.Core/Result.Success.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System;
using System.Threading.Tasks;

namespace OnixLabs.Core;

Expand Down Expand Up @@ -294,4 +295,25 @@ public override void Throw()
/// </summary>
/// <returns>Returns a <see cref="String"/> that represents the current object.</returns>
public override string ToString() => Value?.ToString() ?? string.Empty;

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public override void Dispose()
{
if (Value is IDisposable disposable)
disposable.Dispose();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
/// </summary>
/// <returns>
/// Returns a task that represents the asynchronous dispose operation.
/// </returns>
public override async ValueTask DisposeAsync()
{
if (Value is IAsyncDisposable disposable)
await disposable.DisposeAsync();
}
}
15 changes: 14 additions & 1 deletion OnixLabs.Core/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static async Task<Result> OfAsync(Func<CancellationToken, Task> func, Can
/// Represents a result value, which signifies the presence of a value or an exception.
/// </summary>
/// <typeparam name="T">The type of the underlying result value.</typeparam>
public abstract class Result<T> : IValueEquatable<Result<T>>
public abstract class Result<T> : IValueEquatable<Result<T>>, IDisposable, IAsyncDisposable
{
/// <summary>
/// Initializes a new instance of the <see cref="Result{T}"/> class.
Expand Down Expand Up @@ -528,4 +528,17 @@ public static async Task<Result<T>> OfAsync(Func<CancellationToken, Task<T>> fun
Failure<T> failure => failure.ToString(),
_ => base.ToString() ?? GetType().FullName ?? nameof(Result<T>)
};

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public abstract void Dispose();

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
/// </summary>
/// <returns>
/// Returns a task that represents the asynchronous dispose operation.
/// </returns>
public abstract ValueTask DisposeAsync();
}
4 changes: 2 additions & 2 deletions OnixLabs.Numerics/OnixLabs.Numerics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<Title>OnixLabs.Numerics</Title>
<Authors>ONIXLabs</Authors>
<Description>ONIXLabs Numerics API for .NET</Description>
<AssemblyVersion>8.11.0</AssemblyVersion>
<AssemblyVersion>8.12.0</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Copyright © ONIXLabs 2020</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<PackageVersion>8.11.0</PackageVersion>
<PackageVersion>8.12.0</PackageVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<Title>OnixLabs.Security.Cryptography</Title>
<Authors>ONIXLabs</Authors>
<Description>ONIXLabs Cryptography API for .NET</Description>
<AssemblyVersion>8.11.0</AssemblyVersion>
<AssemblyVersion>8.12.0</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Copyright © ONIXLabs 2020</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<PackageVersion>8.11.0</PackageVersion>
<PackageVersion>8.12.0</PackageVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions OnixLabs.Security/OnixLabs.Security.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<Title>OnixLabs.Security</Title>
<Authors>ONIXLabs</Authors>
<Description>ONIXLabs Security API for .NET</Description>
<AssemblyVersion>8.11.0</AssemblyVersion>
<AssemblyVersion>8.12.0</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Copyright © ONIXLabs 2020</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<PackageVersion>8.11.0</PackageVersion>
<PackageVersion>8.12.0</PackageVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
Loading