Created
August 25, 2023 14:48
-
-
Save lbialy/49813807a405458d35806c722e8c0b77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "3.3.0" | |
import scala.concurrent.*, ExecutionContext.Implicits.global, duration.* | |
import scala.util.boundary, boundary.* | |
def runsOnAnotherThread(msg: String): Future[Unit] = | |
Future: | |
println(s"This: $msg runs on ${Thread.currentThread.getName}") | |
def testFatals(): Future[String] = | |
boundary: | |
for | |
_ <- runsOnAnotherThread("first") | |
_ = throw OutOfMemoryError() | |
yield "after yield" | |
@main def main = | |
// global exception handler will print OOME to stdout from here but execution will continue | |
// because it happens on another thread, not the main thread | |
val fut = testFatals() | |
println(fut) | |
Await.result(fut, Duration.Inf) // this will hang, this Future will NEVER be resolved | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment