Skip to content

Support IAsyncEnumerable returns in SignalR hubs#6791

Merged
halter73 merged 7 commits into
masterfrom
halter73/5357
Feb 25, 2019
Merged

Support IAsyncEnumerable returns in SignalR hubs#6791
halter73 merged 7 commits into
masterfrom
halter73/5357

Conversation

@halter73
Copy link
Copy Markdown
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
Comment thread src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs Outdated
Comment thread src/SignalR/server/Core/src/Internal/AsyncEnumeratorAdapters.cs Outdated
Comment thread src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs Outdated
Comment thread src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs Outdated
Comment thread src/SignalR/samples/SignalRSamples/wwwroot/streaming.html
@halter73 halter73 added the blocked The work on this issue is blocked due to some dependency label Feb 5, 2019
@halter73
Copy link
Copy Markdown
Member Author

halter73 commented Feb 5, 2019

Waiting on #7005

Comment thread src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs Outdated
@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
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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