Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何在akka http中完成响应后进行清理?_Scala_File_Http_Akka - Fatal编程技术网

Scala 如何在akka http中完成响应后进行清理?

Scala 如何在akka http中完成响应后进行清理?,scala,file,http,akka,Scala,File,Http,Akka,我生成一个文件作为响应发送。响应下载后,您希望删除该文件.csv path("hello") { get { complete(HttpEntity.fromFile(ContentTypes.`text/csv(UTF-8)`,file.csv)) } } 这就是解决办法 val source = FileIO.fromPath(file.toPath) .watchTermination() { case (

我生成一个文件作为响应发送。响应下载后,您希望删除该文件.csv

path("hello") {
    get {
        complete(HttpEntity.fromFile(ContentTypes.`text/csv(UTF-8)`,file.csv))
   }
  }
这就是解决办法

  val source = FileIO.fromPath(file.toPath)
                      .watchTermination() { case (_, result) =>
                        result.onComplete(_ => {
                          file.delete()
                          log.info(s"file Deleted  ${file.getPath}")
                        }
                        )
                      }
     complete(HttpEntity(ContentTypes.`text/csv(UTF-8)`, source))
这对我来说很好