Simulating the Elapse of Time

Although the stub used in the previous example will return correct results, it still doesn't effectively simulate the passage of time. One way we can create a more convincing stub is by making it take time. One thing that is very important is that any method that doesn't return immediately should take an IScheduler parameter. We'll see why this is important later in this chapter, but the essential rule is, if you use any Operator that takes an optional IScheduler, make sure to pass it your custom one.

IObservable<string> FetchWebpageOnDialup(string url, IScheduler scheduler = null) {     // Fetch the result, but simulate a slow connection     return FetchWebpageStub(url)         .Delay(TimeSpan.FromSeconds(5.0), ...

Get Programming Reactive Extensions and LINQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.