=htc #19834 Replaced PushStage based captureTermination with GraphStage
* Move promise completion success into postStop to simplify impl
This commit is contained in:
parent
598799d5ae
commit
4a8018f63f
1 changed files with 17 additions and 9 deletions
|
|
@ -63,17 +63,25 @@ private[http] object StreamUtils {
|
|||
|
||||
def captureTermination[T, Mat](source: Source[T, Mat]): (Source[T, Mat], Future[Unit]) = {
|
||||
val promise = Promise[Unit]()
|
||||
val transformer = new PushStage[T, T] {
|
||||
def onPush(element: T, ctx: Context[T]) = ctx.push(element)
|
||||
override def onUpstreamFailure(cause: Throwable, ctx: Context[T]) = {
|
||||
promise.failure(cause)
|
||||
ctx.fail(cause)
|
||||
}
|
||||
override def postStop(): Unit = {
|
||||
promise.trySuccess(())
|
||||
val transformer = new SimpleLinearGraphStage[T] {
|
||||
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) with InHandler with OutHandler {
|
||||
override def onPush(): Unit = push(out, grab(in))
|
||||
|
||||
override def onPull(): Unit = pull(in)
|
||||
|
||||
override def onUpstreamFailure(ex: Throwable): Unit = {
|
||||
promise.failure(ex)
|
||||
failStage(ex)
|
||||
}
|
||||
|
||||
override def postStop(): Unit = {
|
||||
promise.trySuccess(())
|
||||
}
|
||||
|
||||
setHandlers(in, out, this)
|
||||
}
|
||||
}
|
||||
source.transform(() ⇒ transformer) -> promise.future
|
||||
source.via(transformer) -> promise.future
|
||||
}
|
||||
|
||||
def sliceBytesTransformer(start: Long, length: Long): Flow[ByteString, ByteString, NotUsed] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue