Skip to content
Permalink
Browse files

Make IO code agnostic about effects

  • Loading branch information
moradology authored and pomadchin committed Oct 15, 2018
1 parent f9f2ef5 commit 57212450b2af58f8259ca4daa53c4f958374f24c
Showing with 5 additions and 5 deletions.
  1. +5 −5 spark/src/main/scala/geotrellis/spark/util/TaskUtils.scala
@@ -29,16 +29,16 @@ object TaskUtils extends App {
* @param p returns true for exceptions that trigger a backoff and retry
*/

implicit class IOBackoff[A](ioa: IO[A]) {
def retryEBO(p: (Throwable => Boolean))(implicit timer: Timer[IO]): IO[A] = {
def help(count: Int): IO[A] = {
implicit class IOBackoff[A, F[_]: Effect: Timer: Sync](ioa: F[A]) {
def retryEBO(p: (Throwable => Boolean)): F[A] = {
def help(count: Int): F[A] = {
val base: Duration = 52.milliseconds
val timeout = base * Random.nextInt(math.pow(2, count).toInt) // .extInt is [), implying -1
val actualDelay = FiniteDuration(timeout.toMillis, MILLISECONDS)

ioa.handleErrorWith { error =>
if(p(error)) IO.sleep(actualDelay) *> help(count + 1)
else IO.raiseError(error)
if(p(error)) implicitly[Timer[F]].sleep(actualDelay) *> help(count + 1)
else implicitly[Sync[F]].raiseError(error)
}
}
help(0)

0 comments on commit 5721245

Please sign in to comment.
You can’t perform that action at this time.