@@ -40,18 +40,17 @@ 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
46- import cats .syntax ._
47- import cats .syntax .all ._
46+ import cats .syntax .*
47+ import cats .syntax .all .*
4848
4949import scala .annotation .unchecked .uncheckedVariance
50- import scala .concurrent ._
51- import scala .concurrent .duration ._
50+ import scala .concurrent .*
51+ import scala .concurrent .duration .*
5252import scala .util .{Failure , Success , Try }
5353import scala .util .control .NonFatal
54-
5554import java .util .UUID
5655import java .util .concurrent .Executor
5756
@@ -632,6 +631,45 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
632631 (FiberIO [A @ uncheckedVariance], OutcomeIO [B ])]] =
633632 IO .racePair(this , that)
634633
634+ /**
635+ * Evaluates the current IO with the given retry `policy`.
636+ *
637+ * @example
638+ * {{{
639+ * val policy = Retry.exponentialBackoff[IO, Throwable](1.second).withMaxRetries(10)
640+ * io.retry(policy)
641+ * }}}
642+ *
643+ * @param policy
644+ * the policy to use
645+ */
646+ def retry (policy : Retry [IO , Throwable ]): IO [A ] =
647+ Retry .retry(policy)(this )
648+
649+ /**
650+ * Evaluates the current IO with the given retry `policy`.
651+ *
652+ * @example
653+ * {{{
654+ * val policy = Retry.exponentialBackoff[IO, Throwable](1.second).withMaxRetries(10)
655+ * io.retry(
656+ * policy,
657+ * (status, err, decision) => IO.println(s"Attempt ${status.retriesTotal}, error: ${err.getMessage}, next: $decision")
658+ * )
659+ * }}}
660+ *
661+ * @param policy
662+ * the policy to use
663+ *
664+ * @param onRetry
665+ * the effect to invoke on every retry decision
666+ */
667+ def retry (
668+ policy : Retry [IO , Throwable ],
669+ onRetry : (Retry .Status , Throwable , Retry .Decision ) => IO [Unit ]
670+ ): IO [A ] =
671+ Retry .retry(policy, onRetry)(this )
672+
635673 /**
636674 * Inverse of `attempt`
637675 *
0 commit comments