Skip to content

Commit 913760a

Browse files
authored
Merge pull request grpc#24530 from MoienTajik/moien/cleanup
C#: make Math service example use async
2 parents 3c17848 + 45be6f2 commit 913760a

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/csharp/Grpc.Examples.MathClient/MathClient.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,30 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515
#endregion
16-
using System;
17-
using System.Runtime.InteropServices;
18-
using System.Threading;
16+
using System.Threading.Tasks;
1917
using Grpc.Core;
2018

2119
namespace Math
2220
{
2321
class MathClient
2422
{
25-
public static void Main(string[] args)
23+
public static async Task Main(string[] args)
2624
{
2725
var channel = new Channel("127.0.0.1", 23456, ChannelCredentials.Insecure);
2826
Math.MathClient client = new Math.MathClient(channel);
2927
MathExamples.DivExample(client);
3028

31-
MathExamples.DivAsyncExample(client).Wait();
29+
await MathExamples.DivAsyncExample(client);
3230

33-
MathExamples.FibExample(client).Wait();
31+
await MathExamples.FibExample(client);
3432

35-
MathExamples.SumExample(client).Wait();
33+
await MathExamples.SumExample(client);
3634

37-
MathExamples.DivManyExample(client).Wait();
35+
await MathExamples.DivManyExample(client);
3836

39-
MathExamples.DependendRequestsExample(client).Wait();
37+
await MathExamples.DependentRequestsExample(client);
4038

41-
channel.ShutdownAsync().Wait();
39+
await channel.ShutdownAsync();
4240
}
4341
}
4442
}

src/csharp/Grpc.Examples.MathServer/MathServer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#endregion
1616

1717
using System;
18-
using System.Runtime.InteropServices;
19-
using System.Threading;
18+
using System.Threading.Tasks;
2019
using Grpc.Core;
2120

2221
namespace Math
@@ -26,7 +25,7 @@ class MainClass
2625
const string Host = "0.0.0.0";
2726
const int Port = 23456;
2827

29-
public static void Main(string[] args)
28+
public static async Task Main(string[] args)
3029
{
3130
Server server = new Server
3231
{
@@ -40,7 +39,7 @@ public static void Main(string[] args)
4039
Console.WriteLine("Press any key to stop the server...");
4140
Console.ReadKey();
4241

43-
server.ShutdownAsync().Wait();
42+
await server.ShutdownAsync();
4443
}
4544
}
4645
}

src/csharp/Grpc.Examples/MathExamples.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ public static async Task DivManyExample(Math.MathClient client)
6969
new DivArgs { Dividend = 100, Divisor = 21 },
7070
new DivArgs { Dividend = 7, Divisor = 2 }
7171
};
72+
7273
using (var call = client.DivMany())
7374
{
7475
await call.RequestStream.WriteAllAsync(divArgsList);
7576
Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToListAsync()));
7677
}
7778
}
7879

79-
public static async Task DependendRequestsExample(Math.MathClient client)
80+
public static async Task DependentRequestsExample(Math.MathClient client)
8081
{
8182
var numbers = new List<Num>
8283
{

src/csharp/Grpc.Examples/MathServiceImpl.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
#endregion
1818

19-
using System;
2019
using System.Collections.Generic;
21-
using System.Threading;
2220
using System.Threading.Tasks;
2321
using Grpc.Core;
2422
using Grpc.Core.Utils;

0 commit comments

Comments
 (0)