Trivial.Interceptor 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Trivial.Interceptor --version 1.0.0                
NuGet\Install-Package Trivial.Interceptor -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Trivial.Interceptor" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Trivial.Interceptor --version 1.0.0                
#r "nuget: Trivial.Interceptor, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Trivial.Interceptor as a Cake Addin
#addin nuget:?package=Trivial.Interceptor&version=1.0.0

// Install Trivial.Interceptor as a Cake Tool
#tool nuget:?package=Trivial.Interceptor&version=1.0.0                

Note: This library/package is also a part of Trivial so no need install this if you have already installed that.

You can set an action with a specific interceptor to control its execution.

In Trivial.Tasks namespace of Trivial.dll library.

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 Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 365 11/9/2021
1.0.0 339 8/15/2021