Problem:
IEnumerable<Signal> feed = GetFeed();
var average1 = feed.MovingAverage(10);
var a开发者_如何学Goverage2 = feed.MovingAverage(20);
var zipped = average1.Zip(average2, (x,y) => Tuple.Create(x,y));
When I iterate through "zipped", GetFeed().GetEnumerator() gets called twice and creates all sorts of synchronization issues. Is there a LINQ operator that can be used to broadcast values from single producer to multiple consumers? I know about Memoize, but in my case I can't predict buffer size to keep slow and fast consumers "happy".
I am thinking about writing my own operator that would keep separate queues for each consumer, but wanted to check if there is an existing solution.
What you want is Reactive Extensions. It's like LINQ to Objects, but in reverse: you don't pull values, they're pushed through observers.
It takes a little while to get used to it, but judging by what you've posted, it's exactly the right model for you.
精彩评论