Skip to content

Commit

Permalink
FAutoCloseableOps
Browse files Browse the repository at this point in the history
  • Loading branch information
jendakol committed Dec 5, 2018
1 parent 22cbaab commit 13f033c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/scala/com/avast/clients/rabbitmq/rabbitmq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.avast.clients
import java.util.concurrent.Executors

import cats.arrow.FunctionK
import cats.effect.{Effect, IO}
import cats.~>
import com.avast.bytes.Bytes
import com.avast.clients.rabbitmq.api._
Expand All @@ -12,6 +13,7 @@ import mainecoon.FunctorK
import monix.eval.Task
import monix.execution.Scheduler

import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.language.{higherKinds, implicitConversions}

Expand Down Expand Up @@ -186,4 +188,13 @@ 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)
}
}

}

0 comments on commit 13f033c

Please sign in to comment.