public FastProvider(IJointSpaceClient client) { Subject <Unit> observed = new Subject <Unit>(); IObservable <Unit> processedTrigger = Observable.When(Observable.And(observed.StartWith(Unit.Default), Observable.Interval(TimeSpan.FromMilliseconds(10)).StartWith(TaskPoolScheduler.Default.Now.Ticks)).Then((x, y) => x)); Processed = processedTrigger.SelectMany(_ => client.GetAmbilightProcessed()).Do(_ => observed.OnNext(Unit.Default)).Publish().RefCount(); }
/// <summary> /// And - Then - When 的操作. /// 本例子的操作, 运行效果, 与 Zip 一致。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAndThenWhen_Click(object sender, EventArgs e) { // 每2秒产生一个数据. (共计10个, 总耗时20秒) var interva2 = Observable.Interval(TimeSpan.FromSeconds(2)).Select(p => Convert.ToInt32(p)).Take(10); // 每3秒产生一个数据. (共计5个, 总耗时15秒) var interva3 = Observable.Interval(TimeSpan.FromSeconds(3)).Select(p => Convert.ToInt32(p)).Take(5); // 使用 And 创建 Pattern 对象. Pattern <int, int> pattern = Observable.And(interva2, interva3); // 使用刚创建的Pattern对象, Then 创建 Plan 对象. Plan <int> plan = pattern.Then(DoJoinWork); Observable.When(plan) // 观察者线程,跑到 WinForm 控件的线程上. .ObserveOn(uiScheduler) .Subscribe(myObserver); }
public void And_ArgumentChecking() { var someObservable = Observable.Return(1); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And <int, int>(null, someObservable)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And <int, int>(someObservable, null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); ReactiveAssert.Throws <ArgumentNullException>(() => Observable.And(someObservable, someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And(someObservable).And <int>(null)); }