The Future is not complete?

前端 未结 2 1851
你的背包
你的背包 2021-01-15 13:18
object Executor extends App {
  implicit val system = ActorSystem()
  implicit val materializer = ActorMaterializer()
  implicit val ec = system.dispatcher
  import          


        
2条回答
  •  一个人的身影
    2021-01-15 13:52

    Coincidently I created almost the same app for testing/playing with Akka Streams. Could the imported implicits cause the problem? This app works fine for me:

    object PrintAllInFile extends App {
      val file = new java.io.File("data.txt")
    
      implicit val system = ActorSystem("test")
      implicit val mat    = ActorMaterializer()
      implicit val ec     = system.dispatcher
    
      SynchronousFileSource(file)
        .to(Sink.outputStream(() => System.out))
        .run()
        .onComplete(_ => system.shutdown())
    }
    

    Note the stopping of the ActorSystem in the 'onComplete'. Otherwise the app will not exit.

提交回复
热议问题