Created
August 17, 2018 01:35
-
-
Save jilen/384e03a4e5da2bbfb7f21957594fb763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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