-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Using IAsyncEnumerable in the .NET Client #8935
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
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2d43e6c
IAsyncEnumerable hacking
mikaelm12 62d681e
delete
mikaelm12 6132874
clean up
mikaelm12 4571de5
adding more tests
mikaelm12 6c4cdae
AsyncEnumerableAdapters
mikaelm12 d819f26
hacking
mikaelm12 71ddc3b
Can cancel token that is passed into GetAsyncEnumerator now
mikaelm12 c050a81
GeneratereferenceSource
mikaelm12 4c36bdb
move AsyncEnumerableAdapters to Shared directory
mikaelm12 48fd1a7
remove
mikaelm12 386cb77
pr fb
mikaelm12 0c51936
new line
mikaelm12 7148302
pr fb
mikaelm12 5ec5582
return IAsyncEnumerable
mikaelm12 9f7d94a
GenerateReferenceSource
mikaelm12 69072ab
Trigger AzDo
mikaelm12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,6 +436,77 @@ private async Task StopAsyncCore(bool disposing) | |
| } | ||
| } | ||
|
|
||
| #if NETCOREAPP3_0 | ||
| public async IAsyncEnumerable<object> StreamAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default) | ||
|
||
| { | ||
| async Task OnStreamCanceled(InvocationRequest irq) | ||
| { | ||
| // We need to take the connection lock in order to ensure we a) have a connection and b) are the only one accessing the write end of the pipe. | ||
| await WaitConnectionLockAsync(); | ||
| try | ||
| { | ||
| if (_connectionState != null) | ||
| { | ||
| Log.SendingCancellation(_logger, irq.InvocationId); | ||
|
|
||
| // Fire and forget, if it fails that means we aren't connected anymore. | ||
| _ = SendHubMessage(new CancelInvocationMessage(irq.InvocationId), irq.CancellationToken); | ||
| } | ||
| else | ||
| { | ||
| Log.UnableToSendCancellation(_logger, irq.InvocationId); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| ReleaseConnectionLock(); | ||
| } | ||
|
|
||
| // Cancel the invocation | ||
| irq.Dispose(); | ||
| } | ||
|
|
||
| var readers = PackageStreamingParams(ref args, out var streamIds); | ||
|
|
||
| CheckDisposed(); | ||
| await WaitConnectionLockAsync(); | ||
|
|
||
| ChannelReader<object> channel; | ||
| try | ||
| { | ||
| CheckDisposed(); | ||
| CheckConnectionActive(nameof(StreamAsyncCore)); | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| // I just want an excuse to use 'irq' as a variable name... | ||
| var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel); | ||
| await InvokeStreamCore(methodName, irq, args, streamIds?.ToArray(), cancellationToken); | ||
|
|
||
| if (cancellationToken.CanBeCanceled) | ||
| { | ||
| cancellationToken.Register(state => _ = OnStreamCanceled((InvocationRequest)state), irq); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| ReleaseConnectionLock(); | ||
| } | ||
|
|
||
| LaunchStreams(readers, cancellationToken); | ||
|
|
||
| //channel.ReadAllAsync() -> Returns IAsyncEnumerable | ||
|
|
||
| while (await channel.WaitToReadAsync()) | ||
| { | ||
| while (channel.TryRead(out var streamItem)) | ||
| { | ||
| yield return streamItem; | ||
| } | ||
| } | ||
mikaelm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #endif | ||
|
|
||
| private async Task<ChannelReader<object>> StreamAsChannelCoreAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken) | ||
| { | ||
| async Task OnStreamCanceled(InvocationRequest irq) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just did
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we should actually be doing here is using the
MakeCancelableAsyncEnumerableFromChannel<T>method on theAsyncEnumerableAdaptersclassThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. We can just share the source for that file for now.