Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private object IOFiberConstants {
final val UncancelableK = 7
final val UnmaskK = 8
final val AttemptK = 9
final val CancelableK = 10

// resume ids
final val ExecR = 0
Expand Down
2 changes: 1 addition & 1 deletion core/js/src/main/scala/cats/effect/IOApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ trait IOApp {
case Left(Outcome.Errored(t)) => IO.raiseError(t)
case Left(Outcome.Succeeded(code)) => code
case Right(Outcome.Errored(t)) => IO.raiseError(t)
case Right(_) => sys.error("impossible")
case Right(_) => IO.delay(sys.error("impossible"))
}
.unsafeRunFiber(
hardExit(cancelCode),
Expand Down
1 change: 1 addition & 0 deletions core/jvm/src/main/java/cats/effect/IOFiberConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class IOFiberConstants {
static final byte UncancelableK = 7;
static final byte UnmaskK = 8;
static final byte AttemptK = 9;
static final byte CancelableK = 10;

// resume ids
static final byte ExecR = 0;
Expand Down
12 changes: 11 additions & 1 deletion core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
* [[onCancel]]
*/
def cancelable(fin: IO[Unit]): IO[A] =
Spawn[IO].cancelable(this, fin)
IO.Cancelable(this, fin)

def forceR[B](that: IO[B]): IO[B] =
// cast is needed here to trick the compiler into avoiding the IO[Any]
Expand Down Expand Up @@ -2059,6 +2059,12 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits with TuplePara
def onCancel[A](ioa: IO[A], fin: IO[Unit]): IO[A] =
ioa.onCancel(fin)

override def cancelable[A](poll: Poll[IO], ioa: IO[A], ack: IO[Unit]): IO[A] =
ioa.cancelable(ack)

override def cancelable[A](ioa: IO[A], ack: IO[Unit]): IO[A] =
ioa.cancelable(ack)

override def bracketFull[A, B](acquire: Poll[IO] => IO[A])(use: A => IO[B])(
release: (A, OutcomeIO[B]) => IO[Unit]): IO[B] =
IO.bracketFull(acquire)(use)(release)
Expand Down Expand Up @@ -2328,6 +2334,10 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits with TuplePara
def tag = 24
}

private[effect] final case class Cancelable[A](f: IO[A], ack: IO[Unit]) extends IO[A] {
def tag = 25
}

// INTERNAL, only created by the runloop itself as the terminal state of several operations
private[effect] case object EndFiber extends IO[Nothing] {
def tag = -1
Expand Down
Loading
Loading