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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 objectT
.ThrottledLoader0
is a decorator of theLoader0
. It caches the last output of theLoader0
. The cached value expired after 0.5s (in the example). Each time we ask for the output of the functionLoader0
, theThrottledLoader0
will return the cached value if it is not expired, otherwise it will re-compute the output value by invoking theLoader0
again.ThrottledLoader0
add the throttling effect on the functionLoader0
so that if you call this function 10000 times (to get theT
output), you will only get the cached value in the decorator. The real functionLoader0
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 theCustomerLocker
object are free. - After 100 mili-second of waiting:
TimeOutException
Product | Versions 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.
-
.NETStandard 2.0
- System.Threading.Channels (>= 8.0.0)
-
.NETStandard 2.1
- System.Threading.Channels (>= 8.0.0)
-
net6.0
- System.Threading.Channels (>= 8.0.0)
-
net7.0
- System.Threading.Channels (>= 8.0.0)
-
net8.0
- System.Threading.Channels (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.