Skip to content

Commit

Permalink
If you have a function that is throttled to run at most once every 1 …
Browse files Browse the repository at this point in the history
…second with leading and trailing executions, and you invoke it twice at 0.0s, then it will execute once at 0.0s and once at 1.0s. However, a third invocation at 1.2s must not execute until 2.0s, since the duration between the second and third executions would otherwise be 0.2s, which is less than the minimum duration of 1.0s specified.
  • Loading branch information
Aldaviva committed Sep 11, 2020
1 parent b01e86f commit dc25cd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ThrottleDebounce/DebouncerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ internal DebouncerImpl(Delegate rateLimitedCallback, TimeSpan wait, bool leading
private void WaitTimeHasElapsed() {
if (Interlocked.Exchange(ref queuedInvocations, 0) > 0) {
mostRecentResult = (TResult) rateLimitedCallback.DynamicInvoke(mostRecentInvocationParameters);

minTimer.Stop();
minTimer.Start();
maxTimer?.Start();
}
}

Expand Down
6 changes: 3 additions & 3 deletions ThrottleDebounce/ThrottleDebounce.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
Expand All @@ -7,9 +7,9 @@
<Authors>Ben Hutchison</Authors>
<Company>Blue Jeans Network, Inc.</Company>
<Product>ThrottleDebounce</Product>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<Description>Rate limit your actions and funcs by throttling and debouncing them.</Description>
<Copyright>2019 Blue Jeans Network, Inc.</Copyright>
<Copyright>2020 Blue Jeans Network, Inc.</Copyright>
<PackageProjectUrl>https://github.com/Aldaviva/ThrottleDebounce</PackageProjectUrl>
<RepositoryUrl>https://github.com/Aldaviva/ThrottleDebounce.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit dc25cd1

Please sign in to comment.