Advertisement
Guest User

Untitled

a guest
Mar 19th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.39 KB | None | 0 0
  1.  
  2. fun <A> IO<A>.retry(shouldRetry: (count: Int, error: Throwable) -> Boolean): IO<A> =
  3.     handleErrorWith { withRetry(it, 1, shouldRetry) }
  4.  
  5. fun <A> IO<A>.withRetry(err: Throwable, count: Int, shouldRetry: (count: Int, error: Throwable) -> Boolean): IO<A> =
  6.     if (!shouldRetry(count, err)) IO.raiseError(err)
  7.     else handleErrorWith {
  8.         withRetry(it, count + 1, shouldRetry)
  9.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement