Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: block in F using F.blocking instead of scala.concurrent.blocking #717

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ package grpc
package syntax

import java.util.concurrent.TimeUnit
import scala.concurrent._
import cats.effect._
import cats.syntax.all._
import io.grpc.{ManagedChannel, ManagedChannelBuilder}

trait ManagedChannelBuilderSyntax {
Expand All @@ -48,13 +48,11 @@ final class ManagedChannelBuilderOps[MCB <: ManagedChannelBuilder[MCB]](val buil
*/
def resource[F[_]](implicit F: Sync[F]): Resource[F, ManagedChannel] =
resourceWithShutdown { ch =>
F.delay {
ch.shutdown()
if (!blocking(ch.awaitTermination(30, TimeUnit.SECONDS))) {
ch.shutdownNow()
()
}
}
for {
_ <- F.delay(ch.shutdown())
terminated <- F.interruptible(ch.awaitTermination(30, TimeUnit.SECONDS))
_ <- F.unlessA(terminated)(F.delay(ch.shutdownNow()))
} yield (())
}

/** Builds a `ManagedChannel` into a resource. The managed channel is shut down when the resource is released.
Expand Down
14 changes: 6 additions & 8 deletions runtime/src/main/scala/fs2/grpc/syntax/ServerBuilderSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ package grpc
package syntax

import java.util.concurrent.TimeUnit
import scala.concurrent._
import cats.effect._
import cats.syntax.all._
import io.grpc.{Server, ServerBuilder}

trait ServerBuilderSyntax {
Expand All @@ -45,13 +45,11 @@ final class ServerBuilderOps[SB <: ServerBuilder[SB]](val builder: SB) extends A
*/
def resource[F[_]](implicit F: Sync[F]): Resource[F, Server] =
resourceWithShutdown { server =>
F.delay {
server.shutdown()
if (!blocking(server.awaitTermination(30, TimeUnit.SECONDS))) {
server.shutdownNow()
()
}
}
for {
_ <- F.delay(server.shutdown())
terminated <- F.interruptible(server.awaitTermination(30, TimeUnit.SECONDS))
_ <- F.unlessA(terminated)(F.delay(server.shutdownNow()))
} yield (())
}

/** Builds a `Server` into a resource. The server is shut down when the resource is released.
Expand Down