本文整理汇总了C#中Subject.GroupByUntil方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.GroupByUntil方法的具体用法?C# Subject.GroupByUntil怎么用?C# Subject.GroupByUntil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.GroupByUntil方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BugGroupByUntilFromHell
public static void BugGroupByUntilFromHell()
{
Subject<int> s = new Subject<int>();
var obs = s.GroupByUntil(i => i % 5, g => g.Throttle(TimeSpan.FromSeconds(1.0)));
obs.Subscribe((o) =>
{
Console.WriteLine("Start1 " + o.Key);
o.Subscribe(oo =>
{
Console.WriteLine(oo);
},
() =>
{
Console.WriteLine("end1");
});
}, () =>
{
});
s.OnNext(1);
s.OnNext(1);
Thread.Sleep(1500);
s.OnNext(1);
var dos = obs.Subscribe((o) =>
{
Console.WriteLine("\tStart2 " + o.Key);
o.Subscribe(oo =>
{
Console.WriteLine("\t" + oo);
},
() =>
{
Console.WriteLine("\tend2");
});
});
s.OnNext(1);
s.OnNext(1);
Thread.Sleep(1500);
s.OnNext(1);
s.OnNext(1);
s.OnNext(1);
Thread.Sleep(1500);
s.OnNext(1);
s.OnNext(1);
dos.Dispose();
Console.WriteLine("\tkilled");
s.OnNext(1);
s.OnNext(1);
s.OnNext(1);
Thread.Sleep(2000);
s.OnNext(1);
s.OnNext(1);
Thread.Sleep(2000);
//Why the first subscription do not finish ?
}
示例2: ThrottlingEventAggregator
public ThrottlingEventAggregator(int period)
{
Contract.Requires<ArgumentOutOfRangeException>(period > 0);
_eventsSubject = new Subject<Tuple<object, Action<Action>>>();
_eventsSubscription = _eventsSubject
.GroupByUntil(x => x.Item1.GetType(), group => group.Throttle(TimeSpan.FromTicks(period)))
.SelectMany(x => x.TakeLast(1))
.Subscribe(Dispatch);
_eventAggregator = new EventAggregator();
}