diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-07-16 23:12:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-16 23:12:32 -0500 |
| commit | 19174cc478118010e6e39098fd2aa4e5a570a03f (patch) | |
| tree | 3decdf68911dfbf9c00b87a959e048601b259d0d /src | |
| parent | 71739c2daf8ed3b0d878b1df7c432d7ff0dc6789 (diff) | |
| parent | 113e92e271825cb0690bee5ff7c11991d7f09c00 (diff) | |
| download | slskd-19174cc478118010e6e39098fd2aa4e5a570a03f.tar.gz | |
Merge pull request #549 from slskd/flush
Tweak RateLimiter to allow consumers to stop it without flushing
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/RateLimiter.cs | 11 |
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(); } |
