aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2017-08-07 16:26:02 +0200
committerGravatar Jan Tattermusch <jtattermusch@google.com>2017-08-07 16:26:02 +0200
commit4ea8ce19ea2c6d2f9629e06955b0ce62e82266da (patch)
tree02bc21262aabc927d06f7e414e1e3810d5605185 /src/csharp/Grpc.Core
parenta39d9fa040efa1aaec8140b5999352c490a1c817 (diff)
add GrpcEnvironment.ShuttingDown event
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r--src/csharp/Grpc.Core/GrpcEnvironment.cs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs
index 0663ee9215..a466c9fa37 100644
--- a/src/csharp/Grpc.Core/GrpcEnvironment.cs
+++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs
@@ -43,13 +43,15 @@ namespace Grpc.Core
static readonly HashSet<Channel> registeredChannels = new HashSet<Channel>();
static readonly HashSet<Server> registeredServers = new HashSet<Server>();
+ static EventHandler shuttingDown;
+
static ILogger logger = new NullLogger();
readonly GrpcThreadPool threadPool;
readonly DebugStats debugStats = new DebugStats();
readonly AtomicCounter cqPickerCounter = new AtomicCounter();
- bool isClosed;
+ bool isShutdown;
/// <summary>
/// Returns a reference-counted instance of initialized gRPC environment.
@@ -238,6 +240,21 @@ namespace Grpc.Core
}
/// <summary>
+ /// Occurs when <c>GrpcEnvironment</c> is about the start the shutdown logic.
+ /// </summary>
+ public static event EventHandler ShuttingDown
+ {
+ add
+ {
+ shuttingDown += value;
+ }
+ remove
+ {
+ shuttingDown -= value;
+ }
+ }
+
+ /// <summary>
/// Creates gRPC environment.
/// </summary>
private GrpcEnvironment()
@@ -311,13 +328,16 @@ namespace Grpc.Core
/// </summary>
private async Task ShutdownAsync()
{
- if (isClosed)
+ if (isShutdown)
{
- throw new InvalidOperationException("Close has already been called");
+ throw new InvalidOperationException("ShutdownAsync has already been called");
}
+
+ await Task.Run(() => shuttingDown.Invoke(this, null));
+
await threadPool.StopAsync().ConfigureAwait(false);
GrpcNativeShutdown();
- isClosed = true;
+ isShutdown = true;
debugStats.CheckOK();
}