我最近一直在尝试学习ReactiveUI + RxNet ...我都喜欢它们,而且他们都非常介意...我一直在阅读'Programming Reactive Extensions and Linq',其中包括此代码段(已修改,以便它使用最新的类/方法):
var sched = new TestScheduler();
var input = sched.CreateColdObservable(
OnNext(205, 1),
OnNext(305, 10),
OnNext(405, 100),
OnNext(505, 1000),
OnNext(605, 10000),
OnCompleted<int>(1100));
int i = 0;
var windows = input.Window(
Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(100), sched).Take(7),
x => Observable.Timer(TimeSpan.FromMilliseconds(50), sched));
windows.Timestamp(sched)
.Subscribe(obs =>
{
int current = ++i;
Console.WriteLine($"Started Obserable {current} at {obs.Timestamp.Millisecond:n0}ms");
obs.Value.Subscribe(
item =>
Console.WriteLine($" {item} at {sched.Now.Millisecond:n0}ms"),
() => Console.WriteLine($"Ended Obserable {current} at {sched.Now.Millisecond:n0}"));
});
sched.Start();
这是输出:
Started Obserable 1 at 0ms
1 at 0ms
10 at 0ms
100 at 0ms
1000 at 0ms
10000 at 0ms
Ended Obserable 1 at 50
Started Obserable 2 at 100ms
Ended Obserable 2 at 150
Started Obserable 3 at 200ms
Ended Obserable 3 at 250
Started Obserable 4 at 300ms
Ended Obserable 4 at 350
Started Obserable 5 at 400ms
Ended Obserable 5 at 450
Started Obserable 6 at 500ms
Ended Obserable 6 at 550
Started Obserable 7 at 600ms
Ended Obserable 7 at 650
这是预期的输出:
Started Observable 1 at 0ms
Ended Observable 1 at 50ms
Started Observable 2 at 100ms
Ended Observable 2 at 150ms
Started Observable 3 at 200ms
1 at 205ms
Ended Observable 3 at 250ms
Started Observable 4 at 300ms
10 at 305ms
Ended Observable 4 at 350ms
Started Observable 5 at 400ms
100 at 405ms
Ended Observable 5 at 450ms
Started Observable 6 at 500ms
1000 at 505ms
Ended Observable 6 at 550ms
Started Observable 7 at 600ms
10000 at 605ms
Ended Observable 7 at 650ms
知道为什么吗?我错过了什么?
答案 0 :(得分:0)
我不知道您的OnNext方法中有什么,但是Recorded<Notification<T>>
的构造函数(即您在CreateColdObservable方法中输入的内容)是第一个参数,而不是毫秒。所以我会尝试:
var input = sched.CreateColdObservable(
OnNext(2050000, 1),
OnNext(3050000, 10),
OnNext(4050000, 100),
OnNext(5050000, 1000),
OnNext(6050000, 10000),
OnCompleted<int>(11000000));