Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
593a22a9
Commit
593a22a9
authored
7 years ago
by
Jan Tattermusch
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #12099 from jtattermusch/csharp_shutdownevent
Add GrpcEnvironment.ShuttingDown event
parents
cf875b7f
f602869c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
+15
-0
15 additions, 0 deletions
src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
src/csharp/Grpc.Core/GrpcEnvironment.cs
+13
-4
13 additions, 4 deletions
src/csharp/Grpc.Core/GrpcEnvironment.cs
with
28 additions
and
4 deletions
src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
+
15
−
0
View file @
593a22a9
...
...
@@ -18,6 +18,7 @@
using
System
;
using
System.Linq
;
using
System.Threading
;
using
Grpc.Core
;
using
NUnit.Framework
;
...
...
@@ -75,5 +76,19 @@ namespace Grpc.Core.Tests
var
parts
=
coreVersion
.
Split
(
'.'
);
Assert
.
AreEqual
(
3
,
parts
.
Length
);
}
[
Test
]
public
void
ShuttingDownEventIsFired
()
{
var
cts
=
new
CancellationTokenSource
();
var
handler
=
new
EventHandler
((
sender
,
args
)
=>
{
cts
.
Cancel
();
});
GrpcEnvironment
.
ShuttingDown
+=
handler
;
var
env
=
GrpcEnvironment
.
AddRef
();
GrpcEnvironment
.
ReleaseAsync
().
Wait
();
GrpcEnvironment
.
ShuttingDown
-=
handler
;
Assert
.
IsTrue
(
cts
.
Token
.
IsCancellationRequested
);
}
}
}
This diff is collapsed.
Click to expand it.
src/csharp/Grpc.Core/GrpcEnvironment.cs
+
13
−
4
View file @
593a22a9
...
...
@@ -49,7 +49,7 @@ namespace Grpc.Core
readonly
DebugStats
debugStats
=
new
DebugStats
();
readonly
AtomicCounter
cqPickerCounter
=
new
AtomicCounter
();
bool
is
Closed
;
bool
is
Shutdown
;
/// <summary>
/// Returns a reference-counted instance of initialized gRPC environment.
...
...
@@ -237,6 +237,12 @@ namespace Grpc.Core
}
}
/// <summary>
/// Occurs when <c>GrpcEnvironment</c> is about the start the shutdown logic.
/// If <c>GrpcEnvironment</c> is later initialized and shutdown, the event will be fired again (unless unregistered first).
/// </summary>
public
static
event
EventHandler
ShuttingDown
;
/// <summary>
/// Creates gRPC environment.
/// </summary>
...
...
@@ -311,13 +317,16 @@ namespace Grpc.Core
/// </summary>
private
async
Task
ShutdownAsync
()
{
if
(
is
Closed
)
if
(
is
Shutdown
)
{
throw
new
InvalidOperationException
(
"
Close
has already been called"
);
throw
new
InvalidOperationException
(
"
ShutdownAsync
has already been called"
);
}
await
Task
.
Run
(()
=>
ShuttingDown
?.
Invoke
(
this
,
null
)).
ConfigureAwait
(
false
);
await
threadPool
.
StopAsync
().
ConfigureAwait
(
false
);
GrpcNativeShutdown
();
is
Closed
=
true
;
is
Shutdown
=
true
;
debugStats
.
CheckOK
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment