Skip to content

Missing IScheduler parameter

oriches edited this page Dec 30, 2012 · 12 revisions

[Back to Code Analysis & Inspection] (https://github.com/oriches/Resharper.ReactivePlugin/wiki/Code-Analysis-&-Inspection)

Adds a hint highlight to methods which have an overload taking an IScheduler parameter. This is highlighted because not defining an explicit IScheduler instance can cause issues when testing and more importantly can cause threading issues such as deadlocks.

Most methods which define overloads that take an IScheduler parameter usually define the default value to be 'Immediate' or 'Current Thread', unfortunately there doesn't appear to be a list defining the default for the extension method in the Reactive Extensions libraries. More information about the different IScheduler types can be found at http://msdn.microsoft.com/en-us/library/hh229042(v=vs.103).aspx.

Imagine we have to following method, it returns an IObservable<Unit> and the internal implementation uses a couple of Reactive Extension methods which can take an IScheduler instance.

public class ExampleClass
{
    public IObservable<Unit> ExampleMethod(int delay)
    {
        return Observable.Return(Unit.Default)
                         .Delay(TimeSpan.FromSeconds(delay))
                         .Select(unit => unit);
    }
}

With the plugin installed this would be annotated with a Resharper hint as follows:

Missing IScheduler parameter

To resolve the highlight you simple add a IScheduler parameter, in this example it's being passed to the method but it could be resolved by Dependency Injection (DI) via an Inversion of Control container (IoC):

![Fixed IScheduler parameter] (http://oi49.tinypic.com/14kzdqw.jpg)

Clone this wiki locally