Akka thread stays idle and doesn't throw an exception

I am new to Akka / Scala and trying to debug the code below. When he resultSetParserhas an exception, he does not drop it. Instead, a service using this code is simply idle forever.

How can I make my service throw an exception and not just wait in a thread? Is there something like a function watchException()in Akka that I could call right after watchTermination()to make it throw an exception that it sees when processing the stream?

val chunkSource: Source[ChunkStreamPart, NotUsed] =
  Source
    .fromIterator(() => resultSetParser(resultSet) map ChunkStreamPart.apply)
    .watchTermination()((mat : NotUsed, fut : Future[Done]) => {
      watchTermination(fut)
      mat
    })
val chunkEntity = Chunked(ContentTypes.`application/json`, chunkSource)
+4
source share
1 answer

Have you tried to use recover?

For example (not verified):

Source
    .fromIterator(() => resultSetParser(resultSet) map ChunkStreamPart.apply)
    .recover{
        case _: RuntimeException => ??? /* Return ChunkStreamPart here */
    }
+2
source

Source: https://habr.com/ru/post/1688714/


All Articles