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

feat: add async overload for async disposable #148

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
23 changes: 21 additions & 2 deletions src/Arcus.Testing.Core/AsyncDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ private AsyncDisposable(Func<ValueTask> disposeAsync)
/// <summary>
/// Creates an <see cref="AsyncDisposable"/> instance based on an existing synchronous <paramref name="disposable"/>.
/// </summary>
/// <param name="disposable">The synchronous disposable to create as an instance.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="disposable"/> is <c>null</c>.</exception>
public static AsyncDisposable Create(IDisposable disposable)
{
if (disposable is null)
Expand All @@ -31,20 +33,37 @@ public static AsyncDisposable Create(IDisposable disposable)
/// <summary>
/// Creates an <see cref="AsyncDisposable"/> instance based on an existing synchronous <paramref name="dispose"/> operation.
/// </summary>
/// <param name="dispose">The synchronous operation to create as an instance.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="dispose"/> is <c>null</c>.</exception>
public static AsyncDisposable Create(Action dispose)
{
if (dispose is null)
{
throw new ArgumentNullException(nameof(dispose));
}

return new AsyncDisposable(() =>
return Create(() =>
{
dispose();
return ValueTask.CompletedTask;
return Task.CompletedTask;
});
}

/// <summary>
/// Creates an <see cref="AsyncDisposable"/> instance based on an existing asynchronous <paramref name="disposeAsync"/> operation.
/// </summary>
/// <param name="disposeAsync">The asynchronous operation to create as an instance.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="disposeAsync"/> is <c>null</c>.</exception>
public static AsyncDisposable Create(Func<Task> disposeAsync)
{
if (disposeAsync is null)
{
throw new ArgumentNullException(nameof(disposeAsync));
}

return new AsyncDisposable(async () => await disposeAsync());
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
/// </summary>
Expand Down
Loading