aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-07-17 07:27:18 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-07-17 07:27:18 -0500
commitf5bf3be24c2732ac01f0565f1ddd136fe919215e (patch)
treefe009b7bff1a944de438509963f5080f3379594a /src
parentf84f2498c1ef9bc8a0fc09a4848a1a5d27f8f22b (diff)
parent19174cc478118010e6e39098fd2aa4e5a570a03f (diff)
downloadslskd-f5bf3be24c2732ac01f0565f1ddd136fe919215e.tar.gz
Merge remote-tracking branch 'origin/master' into search-status
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();
}