用源完成路由并获得其物化值
Complete route with source and get its materialised value
有一条路线有点像这样:
val route =
path("data") {
get {
val src: Source[ByteString, BoundedSourceQueue[ByteString]] = ???
complete(HttpEntity(ContentTypes.`application/octet-stream`, src))
}
}
我如何访问此源的物化值?
预实现 src
应该可以解决问题。
// will need an implicit ActorSystem/ActorMaterializer in scope
val baseSrc: Source[ByteString, BoundedSourceQueue[ByteString]] = ???
val (bsq, src) = baseSrc.preMaterialize()
// do stuff with bsq...
complete(HttpEntity(ContentTypes.`application/octet-stream`, src))
有一条路线有点像这样:
val route =
path("data") {
get {
val src: Source[ByteString, BoundedSourceQueue[ByteString]] = ???
complete(HttpEntity(ContentTypes.`application/octet-stream`, src))
}
}
我如何访问此源的物化值?
预实现 src
应该可以解决问题。
// will need an implicit ActorSystem/ActorMaterializer in scope
val baseSrc: Source[ByteString, BoundedSourceQueue[ByteString]] = ???
val (bsq, src) = baseSrc.preMaterialize()
// do stuff with bsq...
complete(HttpEntity(ContentTypes.`application/octet-stream`, src))