Skip to content

Commit b052630

Browse files
committed
merge
2 parents ae09da8 + d2980e1 commit b052630

File tree

7 files changed

+77
-10
lines changed

7 files changed

+77
-10
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
<ExampleRefs>local</ExampleRefs> <!-- local or nuget-->
2929
<PBGRPCLibVersion>1.0.147</PBGRPCLibVersion>
30-
<GrpcDotNetVersion>2.36.0</GrpcDotNetVersion>
30+
<GrpcDotNetVersion>2.37.0</GrpcDotNetVersion>
3131
<GoogleProtobufVersion>3.15.6</GoogleProtobufVersion>
32-
<GrpcVersion>2.36.1</GrpcVersion>
32+
<GrpcVersion>2.37.0</GrpcVersion>
3333

3434
<ProtoBufNet2Version>2.4.6</ProtoBufNet2Version>
3535
<ProtoBufNet3Version>3.0.101</ProtoBufNet3Version>

docs/createProtoFile.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# protobuf-net.Reflection
2+
3+
## What is it?
4+
5+
> ProtoBuf DSL (proto2 / proto3) and descriptor tools for protobuf-net
6+
7+
It use to create .proto file for your service
8+
9+
## Install?
10+
11+
Install [`protobuf-net.Reflection`](https://www.nuget.org/packages/protobuf-net.Reflection) on your project
12+
13+
## How use it?
14+
15+
After install change your service and add these lines:
16+
17+
``` c#
18+
var generator = new SchemaGenerator
19+
{
20+
ProtoSyntax = ProtoSyntax.Proto3
21+
};
22+
23+
var schema = generator.GetSchema<ICalculator>(); // there is also a non-generic overload that takes Type
24+
25+
using (var writer = new System.IO.StreamWriter("services.proto"))
26+
{
27+
await writer.WriteAsync(schema);
28+
}
29+
```
30+
31+
Now build your project. Your .proto file is exist on your bin/Debug or bin/Realase
32+
33+
Output example:
34+
35+
```c#
36+
syntax = "proto3";
37+
package Hyper;
38+
39+
message MultiplyRequest {
40+
int32 X = 1;
41+
int32 Y = 2;
42+
}
43+
message MultiplyResult {
44+
int32 Result = 1;
45+
}
46+
service Calculator {
47+
rpc Multiply (MultiplyRequest) returns (MultiplyResult);
48+
}
49+
```

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
- [Package Layout](projects)
66
- [Build Tools ("code-first" focus)](https://protobuf-net.github.io/protobuf-net/build_tools)
77
- [Build Tools ("contract-first" focus)](https://protobuf-net.github.io/protobuf-net/contract_first)
8+
- [Create Proto File](createProtoFile)
89

910
Other Content
1011

11-
- [My talk on gRPC at the .NET Core Summer Event, 2019](talks/gRPC.pptx)
12+
- [My talk on gRPC at the .NET Core Summer Event, 2019](talks/gRPC.pptx)

src/protobuf-net.Grpc.ClientFactory/protobuf-net.Grpc.ClientFactory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
55
<RootNamespace>ProtoBuf.Grpc.ClientFactory</RootNamespace>
66
<LangVersion>preview</LangVersion>
77
</PropertyGroup>

src/protobuf-net.Grpc/CallContext.Streaming.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ private static async IAsyncEnumerable<TResponse> FullDuplexImpl<TRequest, TRespo
3131
[EnumeratorCancellation] CancellationToken cancellationToken)
3232
{
3333
using var allDone = CancellationTokenSource.CreateLinkedTokenSource(context.CancellationToken, cancellationToken);
34+
Task? consumed = null;
3435
try
3536
{
3637
context = new CallContext(context, allDone.Token);
37-
var consumed = Task.Run(() => consumer(source, context).AsTask(), allDone.Token); // note this shares a capture scope
38+
consumed = Task.Run(() => consumer(source, context).AsTask(), allDone.Token); // note this shares a capture scope
3839

3940
await foreach (var value in producer(context).WithCancellation(cancellationToken).ConfigureAwait(false))
4041
{
4142
yield return value;
4243
}
43-
await consumed.ConfigureAwait(false);
4444
}
4545
finally
4646
{
4747
// stop the producer, in any exit scenario
4848
allDone.Cancel();
49+
50+
if (consumed != null)
51+
{
52+
await consumed.ConfigureAwait(false);
53+
}
4954
}
5055
}
5156

@@ -68,10 +73,11 @@ private static async IAsyncEnumerable<TResponse> FullDuplexImpl<TRequest, TRespo
6873
[EnumeratorCancellation] CancellationToken cancellationToken)
6974
{
7075
using var allDone = CancellationTokenSource.CreateLinkedTokenSource(context.CancellationToken, cancellationToken);
76+
Task? consumed = null;
7177
try
7278
{
7379
context = new CallContext(context, allDone.Token);
74-
var consumed = Task.Run(async () =>
80+
consumed = Task.Run(async () =>
7581
{// note this shares a capture scope
7682
await foreach (var value in source.WithCancellation(allDone.Token).ConfigureAwait(false))
7783
{
@@ -82,12 +88,16 @@ private static async IAsyncEnumerable<TResponse> FullDuplexImpl<TRequest, TRespo
8288
{
8389
yield return value;
8490
}
85-
await consumed.ConfigureAwait(false);
8691
}
8792
finally
8893
{
8994
// stop the producer, in any exit scenario
9095
allDone.Cancel();
96+
97+
if (consumed != null)
98+
{
99+
await consumed.ConfigureAwait(false);
100+
}
91101
}
92102
}
93103

src/protobuf-net.Grpc/Configuration/OperationAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace ProtoBuf.Grpc.Configuration
55
{
66
/// <summary>
7-
/// Explicitly indicates that a metho represents a gRPC method
7+
/// Explicitly indicates that a method represents a gRPC method
88
/// </summary>
99
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
1010
[ImmutableObject(true)]

src/protobuf-net.Grpc/Internal/Reshape.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,14 @@ static async Task SendAll<T>(IClientStreamWriter<T> output, IAsyncEnumerable<T>
520520
}
521521
catch
522522
{
523-
allDone.Cancel();
523+
if (!allDone.IsCancellationRequested)
524+
{
525+
try
526+
{
527+
allDone.Cancel();
528+
}
529+
catch { } // calls to "Cancel" can race, ignore the exception if we lose the race
530+
}
524531
throw;
525532
}
526533
}

0 commit comments

Comments
 (0)