Skip to content

Set ConfigureAwait(bool) on IAsyncEnumerators in await foreach loops #6652

@ScottRosenberg2

Description

@ScottRosenberg2

Describe the problem you are trying to solve

Currently CA2007 requires ConfigureAwait(bool) to be set on all instances of awaiting a task.
It does not currently catch cases where you have awaited an IAsyncEnumerator in an await foreach loop.
If you write:
await foreach (var x in someIAsyncEnumerator) { }
I'd like to see it suggest:
await foreach (var x in someIAsyncEnumerator.ConfigureAwait(someBool)) { }

Currently: It does not recognize missing ConfigureAwait on IAsyncEnumerators

Describe suggestions on how to achieve the rule

Create a rule similar to CA2007, or modify CA2007 to correctly identify await foreach IAsyncEnumerators

Additional context

Not having this rule lead to having deadlocks in our code, until manually fixed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions