Merge pull request #24530 from MoienTajik/moien/cleanup

C#: make Math service example use async
pull/24591/head
Jan Tattermusch 4 years ago committed by GitHub
commit 913760a6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      src/csharp/Grpc.Examples.MathClient/MathClient.cs
  2. 7
      src/csharp/Grpc.Examples.MathServer/MathServer.cs
  3. 3
      src/csharp/Grpc.Examples/MathExamples.cs
  4. 2
      src/csharp/Grpc.Examples/MathServiceImpl.cs

@ -13,32 +13,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
namespace Math
{
class MathClient
{
public static void Main(string[] args)
public static async Task Main(string[] args)
{
var channel = new Channel("127.0.0.1", 23456, ChannelCredentials.Insecure);
Math.MathClient client = new Math.MathClient(channel);
MathExamples.DivExample(client);
MathExamples.DivAsyncExample(client).Wait();
await MathExamples.DivAsyncExample(client);
MathExamples.FibExample(client).Wait();
await MathExamples.FibExample(client);
MathExamples.SumExample(client).Wait();
await MathExamples.SumExample(client);
MathExamples.DivManyExample(client).Wait();
await MathExamples.DivManyExample(client);
MathExamples.DependendRequestsExample(client).Wait();
await MathExamples.DependentRequestsExample(client);
channel.ShutdownAsync().Wait();
await channel.ShutdownAsync();
}
}
}

@ -15,8 +15,7 @@
#endregion
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
namespace Math
@ -26,7 +25,7 @@ namespace Math
const string Host = "0.0.0.0";
const int Port = 23456;
public static void Main(string[] args)
public static async Task Main(string[] args)
{
Server server = new Server
{
@ -40,7 +39,7 @@ namespace Math
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
await server.ShutdownAsync();
}
}
}

@ -69,6 +69,7 @@ namespace Math
new DivArgs { Dividend = 100, Divisor = 21 },
new DivArgs { Dividend = 7, Divisor = 2 }
};
using (var call = client.DivMany())
{
await call.RequestStream.WriteAllAsync(divArgsList);
@ -76,7 +77,7 @@ namespace Math
}
}
public static async Task DependendRequestsExample(Math.MathClient client)
public static async Task DependentRequestsExample(Math.MathClient client)
{
var numbers = new List<Num>
{

@ -16,9 +16,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Utils;

Loading…
Cancel
Save