RunningTasks: Add a failing test.
ADD
WalletWasabi.Tests/UnitTests/Nito/AsyncEx/RunningTasksTests.cs
+using System;
+using System.Threading.Tasks;
+using WalletWasabi.Nito.AsyncEx;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.Nito.AsyncEx
+{
+ /// <summary>
+ /// Tests for <see cref="RunningTasks"/> class.
+ /// </summary>
+ public class RunningTasksTests
+ {
+ [Fact]
+ public async Task RemeberWithTestAsync()
+ {
+ AbandonedTasks processingEvents = new();
+
+ using (RunningTasks.RememberWith(processingEvents))
+ {
+ Assert.Equal(1, processingEvents.Count);
+ }
+
+ Assert.Equal(0, processingEvents.Count);
+
+ using (RunningTasks.RememberWith(processingEvents))
+ {
+ Assert.Equal(1, processingEvents.Count);
+ }
+
+ Assert.Equal(0, processingEvents.Count);
+ await processingEvents.WhenAllAsync();
+ }
+ }
+}

MODIFY
WalletWasabi/Nito/AsyncEx/AbandonedTasks.cs
WalletWasabi/Nito/AsyncEx/AbandonedTasks.cs
@@ -27,6 +27,20 @@ namespace WalletWasabi.Nito.AsyncEx
}
}
+ /// <summary>Gets the number of outstanding tasks.</summary>
+ /// <remarks>As a side-effect completed tasks are removed.</remarks>
+ public int Count
+ {
+ get
+ {
+ lock (Lock)
+ {
+ ClearCompletedNoLock();
+ return Tasks.Count;
+ }
+ }
+ }
+
/// <summary>
/// Wait for all tasks to complete.
/// </summary>

RunningTasks: Add a failing test.