From c828c65fec697b65a0de47b377ee479cae9d5e97 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Thu, 10 Nov 2022 11:00:28 +0000 Subject: [PATCH] Fix potential async leak Resolves https://github.com/permutive-engineering/fs2-google-pubsub/issues/371 --- .../pubsub/producer/grpc/internal/FutureInterop.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs2-google-pubsub-grpc/src/main/scala/com/permutive/pubsub/producer/grpc/internal/FutureInterop.scala b/fs2-google-pubsub-grpc/src/main/scala/com/permutive/pubsub/producer/grpc/internal/FutureInterop.scala index 05b7df19..e941f9b3 100644 --- a/fs2-google-pubsub-grpc/src/main/scala/com/permutive/pubsub/producer/grpc/internal/FutureInterop.scala +++ b/fs2-google-pubsub-grpc/src/main/scala/com/permutive/pubsub/producer/grpc/internal/FutureInterop.scala @@ -23,9 +23,9 @@ import com.google.common.util.concurrent.MoreExecutors private[internal] object FutureInterop { def fFromFuture[F[_]: Async, A](future: F[ApiFuture[A]]): F[A] = - future.flatMap { futA => - Async[F] - .async[A] { cb => + Async[F] + .async[A] { cb => + future.flatMap { futA => Sync[F].delay { val futureApi = futA addCallback(futureApi)(cb) @@ -47,7 +47,7 @@ private[internal] object FutureInterop { ) } } - } + } @inline private def addCallback[A](futA: ApiFuture[A])(cb: Either[Throwable, A] => Unit): Unit =