Table of Contents

AsyncActionFactory<TTuple> Class

Definition

Namespace
Cuemon.Threading
Assemblies
Cuemon.Core.dll
Source
src/Cuemon.Core/Threading/AsyncActionFactory.cs

Provides a way of invoking an Action delegate regardless of the amount of parameters provided.

public sealed class AsyncActionFactory<TTuple> : MutableTupleFactory<TTuple> where TTuple : MutableTuple

Type Parameters

TTuple

The type of the n-tuple representation of a MutableTuple.

Inheritance
AsyncActionFactory<TTuple>
Inherited Members

Examples

AsyncActionFactory<T> encapsulates a deferred asynchronous action with typed arguments, with support for cloning for safe concurrent execution. This example creates a factory using AsyncActionFactory.Create<string, int> with a lambda that takes a channel name ("orders") and retry count (3), delays 10ms, and prints them, then calls ExecuteMethodAsync to run it. Key steps include cloning the factory via (AsyncActionFactory<MutableTuple<string, int>>)factory.Clone() and executing the clone separately. Console output displays "orders:3" for both the original and cloned execution, confirming that cloned factories produce identical results.

// Program.cs
using System;
using System.Threading;
using System.Threading.Tasks;
using Cuemon;
using Cuemon.Threading;

var factory = AsyncActionFactory.Create<string, int>(
    async (channel, retryCount, cancellationToken) =>
    {
        await Task.Delay(10, cancellationToken).ConfigureAwait(false);
        Console.WriteLine($"{channel}:{retryCount}");
    },
    "orders",
    3);

await factory.ExecuteMethodAsync(CancellationToken.None);

var clone = (AsyncActionFactory<MutableTuple<string, int>>)factory.Clone();
await clone.ExecuteMethodAsync(CancellationToken.None);

Constructors

Name Description
AsyncActionFactory(Func<TTuple, CancellationToken, Task>, TTuple)

Initializes a new instance of the AsyncActionFactory<TTuple> class.

AsyncActionFactory(Func<TTuple, CancellationToken, Task>, TTuple, Delegate)

Initializes a new instance of the AsyncActionFactory<TTuple> class.

Methods

Name Description
Clone()

Creates a shallow copy of the current AsyncActionFactory<TTuple> object.

ExecuteMethodAsync(CancellationToken)

Executes the delegate associated with this instance.