-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move grpc embedded snippets to projects files (#30077)
* move grpc embedded snippets to projects files * build: use range instead of id for proto files * reword
- Loading branch information
1 parent
2d48b4b
commit d94d3f8
Showing
9 changed files
with
265 additions
and
233 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public override async Task DownloadResults(DataRequest request, | ||
IServerStreamWriter<DataResult> responseStream, ServerCallContext context) | ||
{ | ||
var channel = Channel.CreateBounded<DataResult>(new BoundedChannelOptions(capacity: 5)); | ||
|
||
var consumerTask = Task.Run(async () => | ||
{ | ||
// Consume messages from channel and write to response stream. | ||
await foreach (var message in channel.Reader.ReadAllAsync()) | ||
{ | ||
await responseStream.WriteAsync(message); | ||
} | ||
}); | ||
|
||
var dataChunks = request.Value.Chunk(size: 10); | ||
|
||
// Write messages to channel from multiple threads. | ||
await Task.WhenAll(dataChunks.Select( | ||
async c => | ||
{ | ||
var message = new DataResult { BytesProcessed = c.Length }; | ||
await channel.Writer.WriteAsync(message); | ||
})); | ||
|
||
// Complete writing and wait for consumer to complete. | ||
channel.Writer.Complete(); | ||
await consumerTask; | ||
} |
Oops, something went wrong.