Merge pull request #19528 from ataraxer/wip-http-response-cancellation

Http: HttpEntity stream cancellation
This commit is contained in:
Konrad Malawski 2016-02-10 10:41:27 +01:00
commit b3b0dce9ad
17 changed files with 415 additions and 51 deletions

View file

@ -1201,23 +1201,36 @@ trait FlowOps[+Out, +Mat] {
*
* '''Completes when''' upstream completes
*
* '''Cancels when''' downstream cancels and substreams cancel
* '''Cancels when''' downstream cancels and substreams cancel on `SubstreamCancelStrategy.drain`, downstream
* cancels or any substream cancels on `SubstreamCancelStrategy.propagate`
*
* See also [[FlowOps.splitAfter]].
*/
def splitWhen(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] = {
def splitWhen(substreamCancelStrategy: SubstreamCancelStrategy)(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] = {
val merge = new SubFlowImpl.MergeBack[Out, Repr] {
override def apply[T](flow: Flow[Out, T, NotUsed], breadth: Int): Repr[T] =
via(Split.when(p))
via(Split.when(p, substreamCancelStrategy))
.map(_.via(flow))
.via(new FlattenMerge(breadth))
}
val finish: (Sink[Out, NotUsed]) Closed = s
via(Split.when(p))
via(Split.when(p, substreamCancelStrategy))
.to(Sink.foreach(_.runWith(s)(GraphInterpreter.currentInterpreter.materializer)))
new SubFlowImpl(Flow[Out], merge, finish)
}
/**
* This operation applies the given predicate to all incoming elements and
* emits them to a stream of output streams, always beginning a new one with
* the current element if the given predicate returns true for it.
*
* @see [[#splitWhen]]
*/
def splitWhen(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] =
splitWhen(SubstreamCancelStrategy.drain)(p)
/**
* This operation applies the given predicate to all incoming elements and
* emits them to a stream of output streams. It *ends* the current substream when the
@ -1258,23 +1271,34 @@ trait FlowOps[+Out, +Mat] {
*
* '''Completes when''' upstream completes
*
* '''Cancels when''' downstream cancels and substreams cancel
* '''Cancels when''' downstream cancels and substreams cancel on `SubstreamCancelStrategy.drain`, downstream
* cancels or any substream cancels on `SubstreamCancelStrategy.propagate`
*
* See also [[FlowOps.splitWhen]].
*/
def splitAfter(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] = {
def splitAfter(substreamCancelStrategy: SubstreamCancelStrategy)(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] = {
val merge = new SubFlowImpl.MergeBack[Out, Repr] {
override def apply[T](flow: Flow[Out, T, NotUsed], breadth: Int): Repr[T] =
via(Split.after(p))
via(Split.after(p, substreamCancelStrategy))
.map(_.via(flow))
.via(new FlattenMerge(breadth))
}
val finish: (Sink[Out, NotUsed]) Closed = s
via(Split.after(p))
via(Split.after(p, substreamCancelStrategy))
.to(Sink.foreach(_.runWith(s)(GraphInterpreter.currentInterpreter.materializer)))
new SubFlowImpl(Flow[Out], merge, finish)
}
/**
* This operation applies the given predicate to all incoming elements and
* emits them to a stream of output streams. It *ends* the current substream when the
* predicate is true.
*
* @see [[#splitAfter]]
*/
def splitAfter(p: Out Boolean): SubFlow[Out, Mat, Repr, Closed] =
splitAfter(SubstreamCancelStrategy.drain)(p)
/**
* Transform each input element into a `Source` of output elements that is
* then flattened into the output stream by concatenation,