Update HubProtocol.md (#12509)

* Update HubProtocol.md

Updated the code sample in the protocol doc to reflect the actual programming API

* Update src/SignalR/docs/specs/HubProtocol.md

Co-Authored-By: Brennan <brecon@microsoft.com>
This commit is contained in:
David Fowler 2019-07-25 19:12:14 -07:00 committed by GitHub
parent 331ff2404d
commit e78d17e07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 14 deletions

View File

@ -154,26 +154,26 @@ public int SingleResultFailure(int x, int y)
public IEnumerable<int> Batched(int count) public IEnumerable<int> Batched(int count)
{ {
for(var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
yield return i; yield return i;
} }
} }
[return: Streamed] // This is a made-up attribute that is used to indicate to the .NET Binder that it should stream results public async IAsyncEnumerable<int> Stream(int count)
public IEnumerable<int> Stream(int count)
{ {
for(var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
await Task.Delay(10);
yield return i; yield return i;
} }
} }
[return: Streamed] // This is a made-up attribute that is used to indicate to the .NET Binder that it should stream results public async IAsyncEnumerable<int> StreamFailure(int count)
public IEnumerable<int> StreamFailure(int count)
{ {
for(var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
await Task.Delay(10);
yield return i; yield return i;
} }
throw new Exception("Ran out of data!"); throw new Exception("Ran out of data!");
@ -185,17 +185,13 @@ public void NonBlocking(string caller)
_callers.Add(caller); _callers.Add(caller);
} }
public async Task<int> AddStream(ChannelReader<int> stream) public async Task<int> AddStream(IAsyncEnumerable<int> stream)
{ {
int sum = 0; int sum = 0;
while (await stream.WaitToReadAsync()) await foreach(var item in stream)
{ {
while (stream.TryRead(out var item)) sum += item;
{
sum += item;
}
} }
return sum; return sum;
} }
``` ```