From 9960172ba340a4f154862cd566a3de8e8f43e6bb Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:52:17 +0200 Subject: [PATCH] feat: add async overload for async disposable --- src/Arcus.Testing.Core/AsyncDisposable.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Arcus.Testing.Core/AsyncDisposable.cs b/src/Arcus.Testing.Core/AsyncDisposable.cs index fce5b99b..a7d6aa2a 100644 --- a/src/Arcus.Testing.Core/AsyncDisposable.cs +++ b/src/Arcus.Testing.Core/AsyncDisposable.cs @@ -18,6 +18,8 @@ private AsyncDisposable(Func disposeAsync) /// /// Creates an instance based on an existing synchronous . /// + /// The synchronous disposable to create as an instance. + /// Thrown when the is null. public static AsyncDisposable Create(IDisposable disposable) { if (disposable is null) @@ -31,6 +33,8 @@ public static AsyncDisposable Create(IDisposable disposable) /// /// Creates an instance based on an existing synchronous operation. /// + /// The synchronous operation to create as an instance. + /// Thrown when the is null. public static AsyncDisposable Create(Action dispose) { if (dispose is null) @@ -38,13 +42,28 @@ public static AsyncDisposable Create(Action dispose) throw new ArgumentNullException(nameof(dispose)); } - return new AsyncDisposable(() => + return Create(() => { dispose(); - return ValueTask.CompletedTask; + return Task.CompletedTask; }); } + /// + /// Creates an instance based on an existing asynchronous operation. + /// + /// The asynchronous operation to create as an instance. + /// Thrown when the is null. + public static AsyncDisposable Create(Func disposeAsync) + { + if (disposeAsync is null) + { + throw new ArgumentNullException(nameof(disposeAsync)); + } + + return new AsyncDisposable(async () => await disposeAsync()); + } + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. ///