Trivial.Interceptor
4.0.0
dotnet add package Trivial.Interceptor --version 4.0.0
NuGet\Install-Package Trivial.Interceptor -Version 4.0.0
<PackageReference Include="Trivial.Interceptor" Version="4.0.0" />
paket add Trivial.Interceptor --version 4.0.0
#r "nuget: Trivial.Interceptor, 4.0.0"
// Install Trivial.Interceptor as a Cake Addin #addin nuget:?package=Trivial.Interceptor&version=4.0.0 // Install Trivial.Interceptor as a Cake Tool #tool nuget:?package=Trivial.Interceptor&version=4.0.0
Interceptor is used to control the opportune moment to trigger the action registered.
Note: This library/package is also a part of Trivial so no need install this if you have already installed that.
Add following namespace to your code file to use.
using Trivial.Tasks;
Debounce
You may request to call a specific action several times in a short time but only the last one should be processed and previous ones should be ignored. A sample scenario is real-time search.
var action = Interceptor.Debounce(() => {
// Do something...
}, TimeSpan.FromMilliseconds(200));
// Somewhere to invoke.
action();
Throttle
You may want to request to call an action only once in a short time even if you request to call several times. The rest will be ignored.
var action = Interceptor.Throttle(() => {
// Do something...
}, TimeSpan.FromMilliseconds(10000));
// Somewhere to invoke.
action();
Times
You can define an action can be only processed only when request to call in the specific times range and others will be ignored. A sample scenario is double click.
var action = Interceptor.Times(() => {
// Do something...
}, 2, 2, TimeSpan.FromMilliseconds(200));
// Somewhere to invoke.
action();
Multiple
A handler to process for the specific times and it will be reset after a while.
var action = Interceptor.Multiple(() => {
// Do something...
}, 10, null, TimeSpan.FromMilliseconds(200));
// Somewhere to invoke.
action();
Full control & Concept
You can create a policy named InterceptorPolicy
to determine when the invoking action can be executed.
It contains following properites to set the condition to match.
- Limitation of invoking times. So we can set an optional minimum count and an optional maximum count as a window to allow the invoking actions.
- The counting duration and timeout to auto reset. It is used to reset the above invoking times to zero after a specific time span from the first or last invoking.
- Delay time span to invoke.
- The interceptor mode to determine which one invokes in the above invoking times limitation, e.g. the first one, the last one or all.
Then initialize an instance of Interceptor
or its generic class with the action and policy.
In fact, the above preset interceptors are set with the properties of InterceptorPolicy
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- System.Text.Json (>= 6.0.0)
-
.NETFramework 4.6.1
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 6.0.0)
-
.NETFramework 4.8
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 6.0.0)
-
.NETStandard 2.0
- System.Text.Json (>= 6.0.0)
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.