Skip to content

Commit

Permalink
Unkown IOs always need to be wrapped in Async
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev authored and djspiewak committed May 26, 2019
1 parent ce63156 commit 3abef46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,14 @@ private[effect] object IORunLoop {
bFirst = bindNext.asInstanceOf[Bind]
currentIO = fa

case _ =>
case Async(_, _) =>
// Cannot inline the code of this method — as it would
// box those vars in scala.runtime.ObjectRef!
return suspendInAsync(currentIO.asInstanceOf[IO[A]], bFirst, bRest)
return suspendAsync(currentIO.asInstanceOf[IO.Async[A]], bFirst, bRest)
case _ =>
return Async { (conn, cb) =>
loop(currentIO, conn, cb.asInstanceOf[Callback], null, bFirst, bRest)
}
}

if (hasUnboxed) {
Expand All @@ -234,8 +238,8 @@ private[effect] object IORunLoop {
// $COVERAGE-ON$
}

private def suspendInAsync[A](
currentIO: IO[A],
private def suspendAsync[A](
currentIO: IO.Async[A],
bFirst: Bind,
bRest: CallStack): IO[A] = {

Expand Down
5 changes: 5 additions & 0 deletions laws/shared/src/test/scala/cats/effect/IOTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ class IOTests extends BaseTestsSuite {
io.unsafeRunSync() shouldEqual 2
}

test("uncancelable with unsafeRunSync") {
val io = IO.pure(1).uncancelable
io.unsafeRunSync() shouldBe 1
}

test("map is stack-safe for unsafeRunSync") {
import IOPlatform.{fusionMaxStackDepth => max}
val f = (x: Int) => x + 1
Expand Down

0 comments on commit 3abef46

Please sign in to comment.