Skip to content

Support IAsyncEnumerable returns in SignalR hubs #6791

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 7 commits into from
Feb 25, 2019
Merged

Conversation

halter73
Copy link
Member

I'm waiting for the dotnet SDK to get updated in this repo so I can target C# 8 in our test projects. I'll add tests once we have it.

#5357

@halter73 halter73 added the area-signalr Includes: SignalR clients and servers label Jan 17, 2019
@halter73 halter73 added the blocked The work on this issue is blocked due to some dependency label Feb 5, 2019
@halter73
Copy link
Member Author

halter73 commented Feb 5, 2019

Waiting on #7005

@halter73 halter73 removed the blocked The work on this issue is blocked due to some dependency label Feb 20, 2019
@halter73 halter73 force-pushed the halter73/5357 branch 4 times, most recently from 97c134d to 522a741 Compare February 22, 2019 02:41
{
// 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 Author

Choose a reason for hiding this comment

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

REVIEW: The reason we have to wrap IAsyncEnumerators with non-value-type generic parameters instead of just casting is because we iterate using await foreach which doesn't support flowing a CancellationToken through GetAsyncEnumerator. If we manually iterated over the enumerator, we could save ourselves wrapping in most cases.

So should we manually iterate instead of wrapping the GetAsyncEnumerator call?

@davidfowl

Copy link
Member Author

@halter73 halter73 Feb 22, 2019

Choose a reason for hiding this comment

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

We are the only consumer of the IAsyncEnumerable<object> btw

Copy link
Member

Choose a reason for hiding this comment

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

So we could loop over MoveNextAsync() manually and avoid the BoxedAsyncEnumerator? That sounds nice :D

Copy link
Member

Choose a reason for hiding this comment

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

Yes we should optimize

Copy link
Member Author

Choose a reason for hiding this comment

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

You could have said something before I merged. It was a while loop that manually called GetAsyncEnumerator/MoveNextAsync until you asked me to change it to await foreach @davidfowl 😆

I figured didn't care about the allocation since a bunch of other allocations happen in this code path anyway. I created #7960 to track this with an XS tag. If we want to change this, it's not difficult.

Copy link
Member

Choose a reason for hiding this comment

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

I care, lets fix it in preview4. Assign it to yourself 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm glad you care 😉

@halter73 halter73 force-pushed the halter73/5357 branch 2 times, most recently from 0d00933 to 31c46d8 Compare February 23, 2019 00:14
I was hoping  typeof(T).IsValueType would get evaluated during JIT
compilation which would allow for dead code elimination, but alas:
https://github.com/dotnet/corefx/issues/16217
- Allow hub methods to also return types implementing IAsyncEnumerable
- Flow CancellationToken to IAsyncEnumerable.GetAsyncEnumerator
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.

5 participants