#18021 Sink.seq and FlowOps.limit and .limitWeighted

This commit is contained in:
lolski 2015-11-19 00:11:07 +08:00 committed by Roland Kuhn
parent 52655f2836
commit aadaf15b89
13 changed files with 472 additions and 0 deletions

View file

@ -135,6 +135,19 @@ object Sink {
new Sink(scaladsl.Sink.lastOption[In].mapMaterializedValue(
_.map(akka.japi.Option.fromScalaOption)(ExecutionContexts.sameThreadExecutionContext)))
/**
* A `Sink` that keeps on collecting incoming elements until upstream terminates.
* As upstream may be unbounded, `Flow[T].take` or the stricter ``Flow[T].limit` (and their variants)
* may be used to ensure boundedness.
* Materializes into a Future` of `Seq[T]` containing all the collected elements.
*
* See also [[Flow.limit]], [[Flow.limitWeighted]], [[Flow.take]], [[Flow.takeWithin]], [[Flow.takeWhile]]
*/
def seq[In]: Sink[In, Future[java.util.List[In]]] = {
import scala.collection.JavaConverters._
new Sink(scaladsl.Sink.seq[In].mapMaterializedValue(fut fut.map(sq sq.asJava)(ExecutionContexts.sameThreadExecutionContext)))
}
/**
* Sends the elements of the stream to the given `ActorRef`.
* If the target actor terminates the stream will be canceled.