Skip to content

Commit

Permalink
Fix FAutoCloseableOps.toAutoCloseable
Browse files Browse the repository at this point in the history
  • Loading branch information
jendakol committed Dec 6, 2018
1 parent 89d7796 commit e6a8562
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e6a8562

Please sign in to comment.