O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required