Skip to content

Commit

Permalink
Fix exception handling in cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Aug 30, 2023
1 parent bef5eff commit 90428c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions core/src/main/scala/ox/fork.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def forkCancellable[T](f: => T)(using Ox): CancellableFork[T] =
try Right(result.get())
catch
case e: ExecutionException => Left(e.getCause)
case e: Throwable => Left(e)
// case NonFatal(e) => Left(e)
case NonFatal(e) => Left(e)

override def cancelNow(): Unit =
// will cause the scope to end, interrupting the task if it hasn't yet finished (or potentially never starting it)
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/ox/ForkTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ForkTest extends AnyFlatSpec with Matchers {
val s = Semaphore(0)
scoped {
val f = forkCancellable {
trail.add("started")
// trail.add("started") // uncommenting this makes interruption to get swallowed by SBT's runner from time to time ...
try
s.acquire()
trail.add("main done")
Expand All @@ -159,7 +159,7 @@ class ForkTest extends AnyFlatSpec with Matchers {
}
if trail.get.length == 1
then trail.get shouldBe Vector("cancel done") // the fork wasn't even started
else trail.get shouldBe Vector("started", "interrupted", "interrupted done", "cancel done")
else trail.get shouldBe Vector("interrupted", "interrupted done", "cancel done")
}
}

Expand Down

0 comments on commit 90428c2

Please sign in to comment.