From 113e92e271825cb0690bee5ff7c11991d7f09c00 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Jul 2022 23:05:35 -0500 Subject: make flushing on dispose optional --- src/slskd/Common/RateLimiter.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/slskd/Common') diff --git a/src/slskd/Common/RateLimiter.cs b/src/slskd/Common/RateLimiter.cs index a5d1ba45..e54514d7 100644 --- a/src/slskd/Common/RateLimiter.cs +++ b/src/slskd/Common/RateLimiter.cs @@ -29,7 +29,8 @@ namespace slskd /// Initializes a new instance of the class. /// /// The minimum interval between invocations. - public RateLimiter(int interval) + /// A value indicating whether pending action(s) should be executed during disposal + public RateLimiter(int interval, bool flushOnDispose = false) { Timer = new System.Timers.Timer(interval) { @@ -41,9 +42,12 @@ namespace slskd Staged?.Invoke(); Staged = null; }; + + FlushOnDispose = flushOnDispose; } private bool Disposed { get; set; } + private bool FlushOnDispose { get; } private bool Init { get; set; } private Action Staged { get; set; } private System.Timers.Timer Timer { get; set; } @@ -85,7 +89,10 @@ namespace slskd if (disposing) { // if an action is staged, invoke it to 'flush' - Staged?.Invoke(); + if (FlushOnDispose) + { + Staged?.Invoke(); + } Timer.Dispose(); } -- cgit v1.2.3 From 44b547caea0a87367f040cb116cac107f6eb56b4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 17 Jul 2022 10:55:30 -0500 Subject: docs --- src/slskd/Common/RateLimiter.cs | 2 +- src/slskd/Core/Extensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/slskd/Common') diff --git a/src/slskd/Common/RateLimiter.cs b/src/slskd/Common/RateLimiter.cs index e54514d7..a93bbebf 100644 --- a/src/slskd/Common/RateLimiter.cs +++ b/src/slskd/Common/RateLimiter.cs @@ -29,7 +29,7 @@ namespace slskd /// Initializes a new instance of the class. /// /// The minimum interval between invocations. - /// A value indicating whether pending action(s) should be executed during disposal + /// A value indicating whether pending action(s) should be executed during disposal. public RateLimiter(int interval, bool flushOnDispose = false) { Timer = new System.Timers.Timer(interval) diff --git a/src/slskd/Core/Extensions.cs b/src/slskd/Core/Extensions.cs index d818d387..65942180 100644 --- a/src/slskd/Core/Extensions.cs +++ b/src/slskd/Core/Extensions.cs @@ -75,7 +75,7 @@ namespace slskd /// /// Creates a new instance of from this instance of . /// - /// The UserStatistics instance from which to copy data + /// The UserStatistics instance from which to copy data. /// The new instance. public static UserStatisticsState ToUserStatisticsState(this UserStatistics stats) => new() { -- cgit v1.2.3