Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 观察Rx中的缓冲和组输入_C#_System.reactive - Fatal编程技术网

C# 观察Rx中的缓冲和组输入

C# 观察Rx中的缓冲和组输入,c#,system.reactive,C#,System.reactive,我有一个主题 public ISubject<Price> PriceTicksSubject { get; } 我想要的是能够在五秒钟内将所有缓冲和分组的项作为单个ienumerable发送给客户端。但是,上面的代码每五秒钟调用SendToClient的次数是键数的倍数 有没有关于如何解决此问题的指针?在onNext操作中对缓冲结果进行分组: void DoSubscribe() { PriceTicksSubject.Buffer(TimeSpan.FromMi

我有一个主题

  public ISubject<Price> PriceTicksSubject { get; }
我想要的是能够在五秒钟内将所有缓冲和分组的项作为单个ienumerable发送给客户端。但是,上面的代码每五秒钟调用SendToClient的次数是键数的倍数


有没有关于如何解决此问题的指针?

在onNext操作中对缓冲结果进行分组:

void DoSubscribe()
{
      PriceTicksSubject.Buffer(TimeSpan.FromMilliseconds(5000)).
                Select(buffer => buffer.GroupBy(tick => tick.Key, (key, res) => res.Last())).
                ObserveOn(NewThreadScheduler.Default).Subscribe(x=> 
                        SendtoClients(x));    

}
void DoSubscribe()
{
    PriceTicksSubject.Buffer(TimeSpan.FromMilliseconds(5000))
        .ObserveOn(NewThreadScheduler.Default)
        .Subscribe(bufferedPrices =>
        {
            SendtoClients(bufferedPrices.GroupBy(x => x.Key).Select(g => g.Last()).ToArray());
        });
}