From cd729a5e2f739c3568bc63715387830952f6ceb0 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sun, 8 Sep 2024 15:00:35 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Arman Bilge --- .../shared/src/main/scala/cats/effect/kernel/Resource.scala | 6 +++--- tests/shared/src/test/scala/cats/effect/ResourceSpec.scala | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala b/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala index b98fdf357c..2f3d8f8cf1 100644 --- a/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala +++ b/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala @@ -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) } } @@ -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) } @@ -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) diff --git a/tests/shared/src/test/scala/cats/effect/ResourceSpec.scala b/tests/shared/src/test/scala/cats/effect/ResourceSpec.scala index ccda21b9a8..58dd5eb3fc 100644 --- a/tests/shared/src/test/scala/cats/effect/ResourceSpec.scala +++ b/tests/shared/src/test/scala/cats/effect/ResourceSpec.scala @@ -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)) }(_ =>