Elapsed Time With Cats Effect
I wasn’t really satisfied with the answers posted on SO.
import cats.effect.{ ExitCode, IO, IOApp }
import scala.concurrent.duration.MILLISECONDS
object Elapsed extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
for {
_ <- timer.clock
.monotonic(MILLISECONDS)
.bracket { _ =>
...
} { start =>
timer.clock
.monotonic(MILLISECONDS)
.flatMap(end => ...)
}
} yield ExitCode.Success
}
| Written by Joe O'Pecko