0

What is the best way to accomplish the following in TPL dataflow:

  • I have a TransformManyBlock that for each received element may produce a very long sequence of output elements
  • It would be nice to have an ability to push some elements from the TransformManyBlock further to pipeline not waiting while the whole sequence is generated

As far as I understand this is quite easy in RX, as observer is accessible for data push; but how this shall be done in TDF when blocks are normally bounded with LinkTo and are not aware of each other?

UPD: producer (something wrapped by TransformManyBlock) is asynchronous and it's result looks like Task<IEnumerable<T>>

Pavel Baravik
  • 173
  • 1
  • 9
  • I'm a little confused. I rigged up an example of a `TransformManyBlock` that produces numbers from a single input with a wait (500ms), and the output is processed immediately by a following `ActionBlock` I've linked to the output. It doesn't wait for the whole sequence, but I guess this depends on your implementation. Are you building a list/array then releasing it in one go? – Adam Houldsworth Aug 08 '16 at 07:17
  • Sorry, I missed an important thing - producer is asynchronous and its result looks like Task. This makes the pipeline propagate elements on task completion. In my understanding asynchronous IEnumerable is essentially IObservable, but that's another story. – Pavel Baravik Aug 08 '16 at 07:49
  • 1
    Are you asking how to write a TransformManyBlock that sends each message immediatelly instead of waiting for all of them? The same way you do with IEnumerable - use an iterator and call `yield return` for each individual message, instead of collecting all of them. In simpler terms - just use `yield return someMessage` inside your loop. – Panagiotis Kanavos Aug 11 '16 at 14:28
  • Related: [Is it possible to have any dataflow block type send multiple intermediate results as a result of a single input?](https://stackoverflow.com/questions/62335850/is-it-possible-to-have-any-dataflow-block-type-send-multiple-intermediate-result) – Theodor Zoulias Jun 26 '20 at 16:52

0 Answers0