From e6a856209ad88f7d28f5a82663d91ae2170d5d39 Mon Sep 17 00:00:00 2001 From: kolena Date: Thu, 6 Dec 2018 14:43:34 +0100 Subject: [PATCH] Fix FAutoCloseableOps.toAutoCloseable --- .../scala/com/avast/clients/rabbitmq/rabbitmq.scala | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala b/core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala index 93b2f0d6..4a454b66 100644 --- a/core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala +++ b/core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala @@ -3,7 +3,7 @@ package com.avast.clients import java.util.concurrent.Executors import cats.arrow.FunctionK -import cats.effect.{Effect, IO} +import cats.effect.Effect import cats.~> import com.avast.bytes.Bytes import com.avast.clients.rabbitmq.api._ @@ -189,11 +189,9 @@ package object rabbitmq { } implicit class FAutoCloseableOps[F[_]](val fac: FAutoCloseable[F]) extends AnyVal { - def toAutoCloseable(timeout: Duration = 1.minute)(implicit F: Effect[F]): AutoCloseable = () => { - IO.async[Unit] { cb => - F.runAsync(fac.close())(cb2 => IO(cb(cb2))) - } - .unsafeRunTimed(timeout) + def toAutoCloseable(timeout: Duration = 1.minute)(implicit F: Effect[F], ec: ExecutionContext): AutoCloseable = () => { + implicit val scheduler = Scheduler(ec) + Task.fromEffect(fac.close()).runSyncUnsafe(timeout) } }