JoinBlockT1 T2

suggest change

(Collects 2-3 inputs and combines them into a Tuple)

Like BatchBlock, JoinBlock<T1, T2> and JoinBlock<T1, T2, T3> group data from two or three sources. That is their primary purpose.

For example, a JoinBlock<string, double, int> is an ISourceBlock<Tuple<string, double, int>>.

As with BatchBlock, a join block can operate in greedy or non-greedy mode.

Processing Requests with a Limited Number of Pooled Objects

var throttle = new JoinBlock<ExpensiveObject, Request>();
for(int i=0; i<10; i++) 
{
    throttle.Target1.Post(new ExpensiveObject()); 
}

var processor = new TransformBlock<Tuple<ExpensiveObject, Request>, ExpensiveObject>(pair =>
{
    var resource = pair.Item1;
    var request = pair.Item2;
    
    request.ProcessWith(resource);
    
    return resource;
});

throttle.LinkTo(processor);
processor.LinkTo(throttle.Target1);

This fragment never posts a Request, so the join does not produce a tuple until some other block posts to Target2. ExpensiveObject and Request stand in for your own types.

Introduction to TPL Dataflow by Stephen Toub

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents