aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-07-17 15:03:13 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-07-17 15:03:13 -0500
commita8528fd90b0a5636efd859bc841fa28d267ef84f (patch)
treed018665297ae541d0e5d6ce8cd654623f22d0f05 /src/slskd/Common
parent8432e1395cbe4f5788dec579fbf0516f59847f34 (diff)
parent80acf5a658a4c274cb75fa1befd55f5768769c21 (diff)
downloadslskd-a8528fd90b0a5636efd859bc841fa28d267ef84f.tar.gz
Merge remote-tracking branch 'origin/master' into transfers
Diffstat (limited to 'src/slskd/Common')
-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..a93bbebf 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();
}