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') 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