Skip to content

Commit

Permalink
airframe-grpc: #1513 Add awaitTermination for closing channels (#1516)
Browse files Browse the repository at this point in the history
* airframe-grpc: #1513 Add awaitTermination for closing channels

* Fix close
  • Loading branch information
xerial committed Mar 5, 2021
1 parent 2b4ebca commit cb43c30
Showing 1 changed file with 11 additions and 12 deletions.
Expand Up @@ -143,6 +143,15 @@ object GrpcClientGenerator extends HttpClientGenerator with LogSupport {
generateNestedStub(s)(serviceStub)
}

def channelClose: String =
s"""override def close(): Unit = {
| channel match {
| case m: io.grpc.ManagedChannel =>
| m.shutdownNow().awaitTermination(1, java.util.concurrent.TimeUnit.SECONDS)
| case _ =>
| }
|}""".stripMargin

def syncClientClass: String =
s"""def newSyncClient(
| channel: io.grpc.Channel,
Expand All @@ -160,12 +169,7 @@ object GrpcClientGenerator extends HttpClientGenerator with LogSupport {
| new SyncClient(channel, callOptions, codecFactory)
| }
|
| override def close(): Unit = {
| channel match {
| case m: io.grpc.ManagedChannel => m.shutdownNow()
| case _ =>
| }
| }
|${indent(channelClose)}
|
|${indent(syncClientStub)}
|}
Expand Down Expand Up @@ -255,12 +259,7 @@ object GrpcClientGenerator extends HttpClientGenerator with LogSupport {
| new AsyncClient(channel, callOptions, codecFactory)
| }
|
| override def close(): Unit = {
| channel match {
| case m: io.grpc.ManagedChannel => m.shutdownNow()
| case _ =>
| }
| }
|${indent(channelClose)}
|
|${indent(asyncClientStub)}
|}
Expand Down

0 comments on commit cb43c30

Please sign in to comment.