From 123b5b2f47746a2a9698101c6a6d6fd6388c182c Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Fri, 29 Oct 2021 01:08:18 +0000 Subject: [PATCH] Demo the unsafeRunHere idea --- core/shared/src/main/scala/cats/effect/IO.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index 7b768e3ae7..736642667e 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -699,6 +699,14 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] { () } + def unsafeRunHereAsync(cb: Either[Throwable, A] => Unit)( + implicit runtime: unsafe.IORuntime): Unit = + syncStep.attempt.unsafeRunSync() match { + case Left(ex) => cb(Left(ex)) + case Right(Right(a)) => cb(Right(a)) + case Right(Left(ioa)) => ioa.unsafeRunAsync(cb) + } + def unsafeRunAsyncOutcome(cb: Outcome[Id, Throwable, A @uncheckedVariance] => Unit)( implicit runtime: unsafe.IORuntime): Unit = { unsafeRunFiber(