Skip to content

ForEachAsync continues after cancellation token is cancelled #1940

@da1rren

Description

@da1rren

Bug

Which library version?

System.Reactive.Async 6.0.0-alpha.3
System.Reactive.Linq 5.0.0"

What are the platform(s), environment(s) and related component version(s)?

N/A

What is the use case or problem?

Cancelling ForEachAsync should stop the enumeration.

What is the expected outcome?

Enumeration stopped after token cancelled

What is the actual outcome?

Enumeration continues forever

Do you have a code snippet or project that reproduces the problem?

using System.Reactive.Linq;

var observable = AsyncObservable.Interval(TimeSpan.FromSeconds(1));

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(5));

await observable.ForEachAsync(seconds =>
{
    Console.WriteLine($"Seconds: {seconds}, Is Cancelled: {cancellationTokenSource.Token.IsCancellationRequested}");
}, cancellationTokenSource.Token);
image

I might be just completely misunderstanding but the behaviour seems odd.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions