Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Arman Bilge <armanbilge@gmail.com>
  • Loading branch information
lenguyenthanh and armanbilge authored Sep 8, 2024
1 parent 206020c commit cd729a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ sealed abstract class Resource[F[_], +A] extends Serializable {
def attempt(implicit F: MonadCancelThrow[F]): Resource[F, Either[Throwable, A]] =
Resource.applyFull[F, Either[Throwable, A]] { poll =>
poll(allocatedCase).attempt.map {
case Left(error) => (error.asLeft[A], _ => ().pure[F])
case Right((a, r)) => (a.asRight[Throwable], r)
case error => (error, _ => F.unit)
}
}

Expand All @@ -745,7 +745,7 @@ sealed abstract class Resource[F[_], +A] extends Serializable {

def handleErrorWith[B >: A](f: Throwable => Resource[F, B])(
implicit F: MonadCancelThrow[F]): Resource[F, B] =
attempt(F).flatMap {
attempt.flatMap {
case Right(a) => Resource.pure(a)
case Left(e) => f(e)
}
Expand Down Expand Up @@ -1359,7 +1359,7 @@ abstract private[effect] class ResourceMonadCancel[F[_]]
implicit protected def F: MonadCancel[F, Throwable]

override def attempt[A](fa: Resource[F, A]): Resource[F, Either[Throwable, A]] =
fa.attempt(F)
fa.attempt

def handleErrorWith[A](fa: Resource[F, A])(f: Throwable => Resource[F, A]): Resource[F, A] =
fa.handleErrorWith(f)
Expand Down
2 changes: 1 addition & 1 deletion tests/shared/src/test/scala/cats/effect/ResourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ class ResourceSpec extends BaseSpec with ScalaCheck with Discipline {
}

"acquire is interruptible" in ticked { implicit ticker =>
val sleep = IO.sleep(1.second)
val sleep = IO.never
val timeout = 500.millis
IO.ref(false).flatMap { ref =>
val r = Resource.makeFull[IO, Unit] { poll => poll(sleep).onCancel(ref.set(true)) }(_ =>
Expand Down

0 comments on commit cd729a5

Please sign in to comment.