@@ -40,7 +40,7 @@ import cats.data.Ior
4040import cats .effect .instances .spawn
4141import cats .effect .kernel .CancelScope
4242import cats .effect .kernel .GenTemporal .handleDuration
43- import cats .effect .std .{Backpressure , Console , Env , Supervisor , UUIDGen }
43+ import cats .effect .std .{Backpressure , Console , Env , Retry , Supervisor , UUIDGen }
4444import cats .effect .tracing .{Tracing , TracingEvent }
4545import cats .effect .unsafe .IORuntime
4646import cats .syntax ._
@@ -632,6 +632,45 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
632632 (FiberIO [A @ uncheckedVariance], OutcomeIO [B ])]] =
633633 IO .racePair(this , that)
634634
635+ /**
636+ * Evaluates the current IO with the given retry `policy`.
637+ *
638+ * @example
639+ * {{{
640+ * val policy = Retry.exponentialBackoff[IO, Throwable](1.second).withMaxRetries(10)
641+ * io.retry(policy)
642+ * }}}
643+ *
644+ * @param policy
645+ * the policy to use
646+ */
647+ def retry (policy : Retry [IO , Throwable ]): IO [A ] =
648+ Retry .retry(policy)(this )
649+
650+ /**
651+ * Evaluates the current IO with the given retry `policy`.
652+ *
653+ * @example
654+ * {{{
655+ * val policy = Retry.exponentialBackoff[IO, Throwable](1.second).withMaxRetries(10)
656+ * io.retry(
657+ * policy,
658+ * (status, err, decision) => IO.println(s"Attempt ${status.retriesTotal}, error: ${err.getMessage}, next: $decision")
659+ * )
660+ * }}}
661+ *
662+ * @param policy
663+ * the policy to use
664+ *
665+ * @param onRetry
666+ * the effect to invoke on every retry decision
667+ */
668+ def retry (
669+ policy : Retry [IO , Throwable ],
670+ onRetry : (Retry .Status , Throwable , Retry .Decision ) => IO [Unit ]
671+ ): IO [A ] =
672+ Retry .retry(policy, onRetry)(this )
673+
635674 /**
636675 * Inverse of `attempt`
637676 *
0 commit comments