Skip to content

Remove CancelableEnumerator #10099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2019
Merged

Conversation

mikaelm12
Copy link
Contributor

Fixes: #7960
Context: #6791 (comment)

@mikaelm12 mikaelm12 added the area-signalr Includes: SignalR clients and servers label May 9, 2019
@@ -406,10 +406,11 @@ async Task ExecuteInvocation()

try
{
await foreach (var streamItem in enumerable)
var enumerator = enumerable.GetAsyncEnumerator(streamCts.Token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the enumerator be disposed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the await foreach and call .WithCancellation instead:

await foreach (var streamItem in enumerable.WithCancellation(streamCts.Token))
{
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should

@BrennanConroy
Copy link
Member

We should make CancelableTypedAsyncEnumerable have a factory method that returns an IAsyncEnumberable that way we can avoid allocating the class if the token isn't cancelable.

@@ -51,37 +51,10 @@ public IAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellati
{
Copy link

@dcarr42 dcarr42 May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registration not referenced. Actually is the private class still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is still needed because we need to be able to cancel the inner stream operation from the token passed into GetASyncEnumerator but you bring up a good point about the registration. It should be disposed

@mikaelm12
Copy link
Contributor Author

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact [email protected].

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2481

@mikaelm12
Copy link
Contributor Author

So in another PR we should work to remove more from the AsyncEnumerableAdapters class. There should be support for the [EnumeratorCancellation] parameter attribute which combines the tagged tokens passed into your IAsyncEnumerable returning methods and a token passed into GetAsyncEnumerator

@mikaelm12 mikaelm12 merged commit d37b2ca into master May 10, 2019
@ghost ghost deleted the mikaelm12/RemoveCancelableAsyncEnum branch May 10, 2019 00:04
@@ -98,10 +71,6 @@ public CancelableAsyncEnumerable(IAsyncEnumerable<T> asyncEnumerable, Cancellati

public IAsyncEnumerator<object> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
// Assume that this will be iterated through with await foreach which always passes a default token.
// Instead use the token from the ctor.
Debug.Assert(cancellationToken == default);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaelm12 Why remove this Debug.Assert if we're still not using the cancellationToken being passed in? Don't we now need to link the token sources or assert the cancellationToken is not cancellable? Otherwise we're just ignoring it...

mikaelm12 added a commit that referenced this pull request May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove CancelableAsyncEnumerable
7 participants