Scala main class with futures not terminating

184 views Asked by At

I have a scala main class

object Job extends App {

         def myProcedure() = {
             sqlu"""CALL `dbName`.`update_history();"""
         }

         implicit val system: ActorSystem = ActorSystem()
         implicit val mat: ActorMaterializer = ActorMaterializer()
         implicit val ec = system.dispatcher
         implicit val session: SlickSession = SlickSession.forConfig("my-mysql")
         val proc = session.db.run(myProcedure))
          
         val terminatedF = proc.flatMap { rec =>
              println("value of the procedure ::" + rec)
              session.close()
              system.terminate()
         }
         Await.result(terminatedF, Duration.Inf)
          println("terminated :::")
     }

I see that the value of rec gets printed, and also terminated ::: i.e. last line also gets printed. However the program does not end. Am I missing anything here ?

1

There are 1 answers

0
user9920500 On

This was a problem with user defined threads.

I used Await.result on the last Future and then did sys.exit(0). Also in build.sbt

I used

fork in run := true

This perfectly works