aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-07-16 23:05:35 -0500
committerJP Dillingham <jp@dillingham.me>2022-07-16 23:05:35 -0500
commit113e92e271825cb0690bee5ff7c11991d7f09c00 (patch)
tree3decdf68911dfbf9c00b87a959e048601b259d0d /src
parent71739c2daf8ed3b0d878b1df7c432d7ff0dc6789 (diff)
downloadslskd-113e92e271825cb0690bee5ff7c11991d7f09c00.tar.gz
make flushing on dispose optional
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/RateLimiter.cs11
1 files changed, 9 insertions, 2 deletions
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 <see cref="RateLimiter"/> class.
/// </summary>
/// <param name="interval">The minimum interval between invocations.</param>
- public RateLimiter(int interval)
+ /// <param name="flushOnDispose">A value indicating whether pending action(s) should be executed during disposal</param>
+ 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();
}