本文整理汇总了C#中ISubject.Buffer方法的典型用法代码示例。如果您正苦于以下问题:C# ISubject.Buffer方法的具体用法?C# ISubject.Buffer怎么用?C# ISubject.Buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISubject
的用法示例。
在下文中一共展示了ISubject.Buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpMessagePublisher
public HttpMessagePublisher(IResourceOptionsProvider resourceOptionsProvider)
{
_resourceOptionsProvider = resourceOptionsProvider;
_listenerSubject = new Subject<IMessage>();
_httpHandler = new HttpClientHandler();
_httpClient = new HttpClient(_httpHandler);
// ensure off-request message transport is obsered onto a different thread
_listenerSubject.Buffer(TimeSpan.FromMilliseconds(100)).Subscribe(x =>
{
// TODO: would be nice if the buffer only triggered when it had values
if (x.Any())
{
Observable.Start(async () => await Process(x), TaskPoolScheduler.Default);
}
});
}
示例2: SlowMessagePublisher
public SlowMessagePublisher()
{
_listenerSubject = new Subject<Message>();
// ensure off-request message transport is obsered onto a different thread
_listenerSubject.Buffer(TimeSpan.FromMilliseconds(100)).Subscribe(
x => {
// QUESTION: Is there a way to only let the buffer go if it has something to publish?
if (x.Any())
{
Observable.Start(async () => await Publish(x), TaskPoolScheduler.Default);
}
});
}