可以将一个 ActionBlock link 转换为另一个包含更多参数的 ActionBlock 吗?

Can an ActionBlock link to another ActionBlock with more parameters in it?

我仍然对 TPL DataFlow 有所了解,所以请多多包涵。

我的应用程序要求并行执行队列,同时保持其顺序。这使我找到了 DataFlow 库以及我正在尝试做的事情。我想知道是否有办法 link 一个 ActionBlock 到另一个 ActionBlock,第二个从第一个操作中获取值。
伪示例:

var block1 = new ActionBlock<ByteBuffer>(buffer => {
   // code generating a hash of the byte buffer to pass to next block 
    ulong hash = generateHash(buffer);
   // this is what i would like to pass to the next ActionBlock
    var tup = Tuple<ByteBuffer, ulong>(buffer, along);
}, dataFlowOpts);
var block2 = new ActionBlock<Tuple<ByteBuffer, ulong>(tup => {
    /* code to act on the buffer and hash */
}, dataFlowOpts);

block1.LinkTo(block2); // Is there something like this that would use the correct params?

我想做的事情可行吗?这甚至有意义吗?我将它们分成两个 ActionBlocks 的原因是我想在另一个代码路径中重用 block2(以不同方式散列不同 ByteBuffer 的内容。)

也许有更好的方法?真的,我只是想在对象以并发方式进入时对其进行哈希处理,同时保留 FIFO 顺序,因为它太慢而无法同步进行哈希处理。

只需使用 TransformBlock:

var block1 = new TransformBlock<ByteBuffer, Tuple<ByteBuffer, ulong>>(buffer => {
    // code generating a hash of the byte buffer to pass to next block 
    ulong hash = generateHash(buffer);
    // this is what i would like to pass to the next ActionBlock
    return Tuple<ByteBuffer, ulong>(buffer, along);
}, dataFlowOpts);
var block2 = new ActionBlock<Tuple<ByteBuffer, ulong>(tup => {
    /* code to act on the buffer and hash */
}, dataFlowOpts);

block1.LinkTo(block2); // Is there something like this that would use the correct params?

或者,使用具有两个属性的 DTO class 可能是更好的选择:缓冲区和散列,因为 Tuple 可读性不高。另外,考虑一个关于命名元组的新 C# 特性。