Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

New rule proposal: Async methods should have a CancellationToken parameter #32

@nbarbettini

Description

@nbarbettini

This doesn't apply to all asynchronous methods, but I think it might be a useful rule to have in the toolbox (rulebox?) provided it is disabled by default.

I write a lot of methods like this:

public Task<Response> GetResponse(
    string href,
    CancellationToken cancellationToken = default(CancellationToken))
{ 
    //... 
}

...which is a pattern modeled after the TAP guidelines and Mongo's excellent C# driver.

It's easy to forget the CancellationToken parameter, though, so in my own project I have a short unit test that uses reflection to make sure I haven't forgotten something. That made me think that an analyzer rule might be a better tool for the job! 😄

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions