Skip to content

Instantly share code, notes, and snippets.

@lbialy
Created August 25, 2023 14:48
Show Gist options
  • Save lbialy/49813807a405458d35806c722e8c0b77 to your computer and use it in GitHub Desktop.
Save lbialy/49813807a405458d35806c722e8c0b77 to your computer and use it in GitHub Desktop.
//> 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