Package Description
$ dotnet add package MemoizR.StructuredConcurrency"The world is still short on languages that deal super elegantly and inherently and intuitively with concurrency" Mads Torgersen Lead Designer of C# (https://www.youtube.com/watch?v=Nuw3afaXLUc&t=4402s)
MemoizR is a powerful library that simplifies concurrent state management in .NET. It provides a performant and thread-safe way to handle complex state synchronization across multiple threads, making it ideal for a wide range of applications.
MemoizR draws inspiration from various sources:
var f = new MemoFactory();
var v1 = f.CreateSignal(1);
var m1 = f.CreateMemoizR(async() => await v1.Get());
var m2 = f.CreateMemoizR(async() => await v1.Get() * 2);
var m3 = f.CreateMemoizR(async() => await m1.Get() + await m2.Get());
// Get Values
await m3.Get(); // Calculates m1 + 2 * m1 => (1 + 2 * 1) = 3
// Change
await v1.Set(2); // Setting v1 does not trigger the evaluation of the graph
await m3.Get(); // Calculates m1 + 2 * m1 => (1 + 2 * 2) = 6
await m3.Get(); // No operation, result remains 6
await v1.Set(3); // Setting v1 does not trigger the evaluation of the graph
await v1.Set(2); // Setting v1 does not trigger the evaluation of the graph
await m3.Get(); // No operation, result remains 6 (because the last time the graph was evaluated, v1 was already 2)
MemoizR can also handle scenarios where the graph is not stable at runtime, making it adaptable to changing dependencies.
var m3 = f.CreateMemoizR(async() => await v1.Get() ? await m1.Get() : await m2.Get());
var f = new MemoFactory("DSC");
var child1 = f.CreateConcurrentMapReduce(
async c =>
{
await Task.Delay(3000, c.Token);
return 3;
});
// all tasks get canceled if one fails
var c1 = f.CreateConcurrentMapReduce(
async _ =>
{
await child1.Get();
// Any group work can kick off other group work.
await Task.WhenAll(Enumerable.Range(1, 10)
.Select(x => f.CreateConcurrentMapReduce(
async c =>
{
await Task.Delay(3000, c.Token);
return x;
}).Get()));
return 4;
});
var x = await c1.Get();
Start using MemoizR to simplify and optimize concurrency management in your .NET applications.
Experiment with MemoizR online: https://dotnetfiddle.net/Widget/EWtptc
Example From: Khalid Abuhakmeh