Skip to content

Commit

Permalink
#1: Let throttle take an action and function with no arguments
Browse files Browse the repository at this point in the history
Also bump .NET Framework version for Demo project and copyright year for package.
  • Loading branch information
Aldaviva committed Nov 15, 2019
1 parent 3fe5e8d commit be52896
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>Demo</RootNamespace>
<AssemblyName>Demo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down
20 changes: 10 additions & 10 deletions Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
<ColumnDefinition Width="41*"/>
<ColumnDefinition Width="67*"/>
</Grid.ColumnDefinitions>
<Label Content="Throttled" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="2" Height="23" Width="51"/>
<Label Content="Debounced (trailing)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="3" Height="23" Width="102" />
<Label Content="Debounced (leading)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="4" Height="23" Width="103"/>
<Label x:Name="throttled" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Height="23" Width="201"/>
<Label x:Name="debouncedTrailing" VerticalAlignment="Top" Grid.Column="1" Grid.Row="3" Height="23" Width="201"/>
<Label x:Name="debouncedLeading" VerticalAlignment="Top" Grid.Column="1" Grid.Row="4" Height="23" Width="201"/>
<Label Content="Original" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top"/>
<Label x:Name="original" Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Width="201" Height="23"/>
<Label Content="Debounced (both)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="5" Height="23" Width="103"/>
<Label x:Name="debouncedBoth" Content="" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="5" VerticalAlignment="Top" Width="201"/>
<Label Content="Throttled" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="2" Height="28" Width="113"/>
<Label Content="Debounced (trailing)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="3" Height="28" Width="113" />
<Label Content="Debounced (leading)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="4" Height="28" Width="113"/>
<Label x:Name="throttled" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Height="28" Width="201"/>
<Label x:Name="debouncedTrailing" VerticalAlignment="Top" Grid.Column="1" Grid.Row="3" Height="28" Width="201"/>
<Label x:Name="debouncedLeading" VerticalAlignment="Top" Grid.Column="1" Grid.Row="4" Height="28" Width="201"/>
<Label Content="Original" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="113" Height="29"/>
<Label x:Name="original" Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Width="201" Height="29"/>
<Label Content="Debounced (both)" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="5" Height="28" Width="113"/>
<Label x:Name="debouncedBoth" Content="" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="5" VerticalAlignment="Top" Width="201" Height="28"/>
</Grid>

</Grid>
Expand Down
10 changes: 5 additions & 5 deletions ThrottleDebounce/ThrottleDebounce.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<Authors>Ben Hutchison</Authors>
<Company>Blue Jeans Network, Inc.</Company>
<Product>ThrottleDebounce</Product>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Description>Rate limit your actions and funcs by throttling and debouncing them.</Description>
<Copyright>2018 Blue Jeans Network, Inc.</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/Aldaviva/ThrottleDebounce/master/License.txt</PackageLicenseUrl>
<Copyright>2019 Blue Jeans Network, Inc.</Copyright>
<PackageProjectUrl>https://github.com/Aldaviva/ThrottleDebounce</PackageProjectUrl>
<RepositoryUrl>https://github.com/Aldaviva/ThrottleDebounce</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<RepositoryUrl>https://github.com/Aldaviva/ThrottleDebounce.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>throttle debounce rate limit rate-limit ratelimit</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncludeSource>True</IncludeSource>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

</Project>
10 changes: 10 additions & 0 deletions ThrottleDebounce/Throttler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace ThrottleDebounce {

public static class Throttler {

public static DebouncedFunc<TResult> Throttle<TResult>(Func<TResult> func, TimeSpan wait, bool leading = true, bool trailing = true) {
return new DebouncerImpl<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TResult>(func, wait, leading,
trailing, wait);
}

public static DebouncedFunc<T1, TResult> Throttle<T1, TResult>(Func<T1, TResult> func, TimeSpan wait, bool leading = true, bool trailing = true) {
return new DebouncerImpl<T1, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TResult>(func, wait, leading,
trailing, wait);
Expand Down Expand Up @@ -84,6 +89,11 @@ public static DebouncedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T
return new DebouncerImpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(func, wait, leading, trailing, wait);
}

public static DebouncedAction Throttle(Action action, TimeSpan wait, bool leading = true, bool trailing = true) {
return new DebouncerImpl<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>(action, wait, leading,
trailing, wait);
}

public static DebouncedAction<T1> Throttle<T1>(Action<T1> action, TimeSpan wait, bool leading = true, bool trailing = true) {
return new DebouncerImpl<T1, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>(action, wait, leading,
trailing, wait);
Expand Down
1 change: 1 addition & 0 deletions sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

0 comments on commit be52896

Please sign in to comment.