开发者

Publisher/Subscriber in LINQ?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜