Still playing around with ReactiveUi.
I'm currently having trouble determining when a sequence has ended. I have the following code :
public RxTest()
{
DownloadDocument = ReactiveCommand.CreateAsyncObservable(_ => GetItems().ToObservable());
DownloadDocument.Subscribe(Console.WriteLine, () => Console.WriteLine("Done"));
}
public ReactiveCommand<int> DownloadDocument { get; set; }
public void RunCommand()
{
DownloadDocument.Execute(new object());
}
IEnumerable<int> GetItems()
{
for (int i = 0; i < 20; i++)
{
Thread.Sleep(100);
yield return i;
}
}
The numbers 1 to 19 are printed, but the "Done" does not get printed (ie, OnComplete isn't raised).
The same (similar) code works just fine in pure Rx (I used Linqpad to test this, but also worked when shoe horned into my test application) ...
{
IObservable<int> range = GetItems().ToObservable(Scheduler.NewThread);
range.ObserveOn(Scheduler.Default).Subscribe (Console.WriteLine, () => Console.WriteLine("Done"));
}