File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import java.util.Objects
1515
1616import scala .util .{Failure , Success , Try }
1717import scala .concurrent .{ExecutionContext , Future , Promise }
18+ import scala .util .control .NonFatal
1819
1920/** The base class for state machines generated by the `scala.async.Async.async` macro.
2021 * Not intended to be directly extended in user-written code.
@@ -34,15 +35,14 @@ abstract class FutureStateMachine(execContext: ExecutionContext) extends Functio
3435 /** Assign `i` to the state variable */
3536 protected def state_= (s : Int ): Unit = state$async = s
3637
38+ NonFatal // eagerly classloading NonFatal to reduce the chance of a cascading StackOverflowError in `completeFailure`
39+
3740 /** Complete the state machine with the given failure. */
38- protected def completeFailure (t : Throwable ): Unit = {
39- //
40- // TODO https://github.com/scala/scala-async/issues/243
41- //
42- // scala-async accidentally started catching NonFatal exceptions in:
43- // https://github.com/scala/scala-async/commit/e3ff0382ae4e015fc69da8335450718951714982#diff-136ab0b6ecaee5d240cd109e2b17ccb2R411
44- // This follows the new behaviour but should we fix the regression?
45- result$async.complete(Failure (t))
41+ protected def completeFailure (t : Throwable ): Unit = t match {
42+ case NonFatal (t) =>
43+ result$async.complete(Failure (t))
44+ case _ =>
45+ throw t
4646 }
4747
4848 /** Complete the state machine with the given value. */
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ class ExceptionalTest {
1818 }
1919
2020 @ Test
21- @ Ignore // TODO https://github.com/scala/scala-async/issues/243
2221 def nonFatalNotCaughtAsync (): Unit = {
2322 check { implicit ec =>
2423 async {
You can’t perform that action at this time.
0 commit comments