Skip to content

Instantly share code, notes, and snippets.

@jilen
Created August 17, 2018 01:35
Show Gist options
  • Save jilen/384e03a4e5da2bbfb7f21957594fb763 to your computer and use it in GitHub Desktop.
Save jilen/384e03a4e5da2bbfb7f21957594fb763 to your computer and use it in GitHub Desktop.
import cats.syntax.all._
import cats.effect._
import scala.concurrent.duration._
import scala.language.higherKinds
object Foo {
def setInterval[F[_]](duration: FiniteDuration)(
fa: F[Unit]
)(implicit F: ConcurrentEffect[F], T: Timer[F]): F[IO[Unit]] = {
def run: F[Unit] = {
T.sleep(duration) *>
F.liftIO(F.runAsync(F.suspend(run))(_ => IO.unit)) *> fa
}
F.liftIO(F.runCancelable(run)(_ => IO.unit))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment