ToolsPack.Thread 3.1.0

dotnet add package ToolsPack.Thread --version 3.1.0
NuGet\Install-Package ToolsPack.Thread -Version 3.1.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="ToolsPack.Thread" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolsPack.Thread --version 3.1.0
#r "nuget: ToolsPack.Thread, 3.1.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 ToolsPack.Thread as a Cake Addin
#addin nuget:?package=ToolsPack.Thread&version=3.1.0

// Install ToolsPack.Thread as a Cake Tool
#tool nuget:?package=ToolsPack.Thread&version=3.1.0

ToolsPack.Thread

ThrottledLoader0

Inspire from the Throttling technique in the javascript world.

Problem it try to solve

//A generic loader with zero argument
public delegate T Loader0<T>();

Loader0<int> lo = () => { read_database; return i; }

var result = lo(); // read_database every call
for (1..10000) { result = lo(); }  //BAD: call read_database 10000 times

ThrottledLoader0<int> tlo = new ThrottledLoader0<int>(lo, 500); //0.5s
var result = tlo.GetValue(); // read_database (at most once every 0.5s)
for (1..10000) { result = tlo.GetValue(); }  //GOOD: read_database only once every 0.5s
  • Loader0<T>() is a function which take zero argument (no input) and return an object T.
  • ThrottledLoader0 is a decorator of the Loader0. It caches the last output of the Loader0. The cached value expired after 0.5s (in the example). Each time we ask for the output of the function Loader0, the ThrottledLoader0 will return the cached value if it is not expired, otherwise it will re-compute the output value by invoking the Loader0 again.
  • ThrottledLoader0 add the throttling effect on the function Loader0 so that if you call this function 10000 times (to get the T output), you will only get the cached value in the decorator. The real function Loader0 will be called only once every 0.5s

ThrottledLoaderAsync0

// A generic loader with zero argument
public delegate Task<T> LoaderAsync0<T>();

LoaderAsync0<int> lo = async () => { await select_from_database; return i; }

var result = await lo(); // select_from_database every call
for (1..10000) { result = await lo(); }  //BAD: select_from_database 10000 times

ThrottledLoaderAsync0<int> tlo = new ThrottledLoaderAsync0<int>(lo, 500); //0.5s
var result = await tlo.GetValue(); // select_from_database at most once every 0.5s
for (1..10000) { result = await tlo.GetValueAsync(); }  //GOOD: select_from_database only once every 0.5s

NamedLocker

static readonly NamedLocker<string> CustomerLocker = new NamedLocker<string>();
customerLocker.RunWithLock("Peter.Buy", () =>
{
	//synchronized code
}
  • The "synchronized code" will wait for other "Peter.Buy"` key free.

MultiNamedTimedLocker

static readonly MultiNamedTimedLocker<string> CustomerLocker = new MultiNamedTimedLocker<string>();

using (customerLocker.Lock(new[] {"peter", "david"}, 100))
{
	//synchronized code
}
  • The "synchronized code" will wait until the "peter" and "david" key of the CustomerLocker object are free.
  • After 100 mili-second of waiting: TimeOutException
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 is compatible.  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 is compatible.  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 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  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
3.1.0 102 2/8/2024
3.0.3 89 2/8/2024
3.0.2 76 2/8/2024
3.0.1 419 11/27/2022
3.0.0 1,348 7/5/2022
2.0.4 1,603 5/14/2020
2.0.3 468 4/13/2020
2.0.2 574 4/4/2020
2.0.1 542 12/23/2019
2.0.0 534 5/31/2019
1.0.0.1 1,465 11/19/2015
1.0.0 1,232 11/15/2015