object Sink
- Source
- Sink.scala
- Alphabetic
- By Inheritance
- Sink
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
def
actorRef[T](ref: ActorRef, onCompleteMessage: Any): Sink[T, NotUsed]
Sends the elements of the stream to the given
ActorRef.Sends the elements of the stream to the given
ActorRef. If the target actor terminates the stream will be canceled. When the stream is completed successfully the givenonCompleteMessagewill be sent to the destination actor. When the stream is completed with failure a akka.actor.Status.Failure message will be sent to the destination actor.It will request at most
maxInputBufferSizenumber of elements from upstream, but there is no back-pressure signal from the destination actor, i.e. if the actor is not consuming the messages fast enough the mailbox of the actor will grow. For potentially slow consumer actors it is recommended to use a bounded mailbox with zeromailbox-push-timeout-timeor use a rate limiting operator in front of thisSink. -
def
actorRefWithAck[T](ref: ActorRef, onInitMessage: Any, ackMessage: Any, onCompleteMessage: Any, onFailureMessage: (Throwable) ⇒ Any = Status.Failure): Sink[T, NotUsed]
Sends the elements of the stream to the given
ActorRefthat sends back back-pressure signal.Sends the elements of the stream to the given
ActorRefthat sends back back-pressure signal. First element is alwaysonInitMessage, then stream is waiting for acknowledgement messageackMessagefrom the given actor which means that it is ready to process elements. It also requiresackMessagemessage after each stream element to make backpressure work.If the target actor terminates the stream will be canceled. When the stream is completed successfully the given
onCompleteMessagewill be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)function will be sent to the destination actor. -
def
asPublisher[T](fanout: Boolean): Sink[T, Publisher[T]]
A
Sinkthat materializes into a org.reactivestreams.Publisher.A
Sinkthat materializes into a org.reactivestreams.Publisher.If
fanoutistrue, the materializedPublisherwill support multipleSubscribers and the size of theinputBufferconfigured for this operator becomes the maximum number of elements that the fastest org.reactivestreams.Subscriber can be ahead of the slowest one before slowing the processing down due to back pressure.If
fanoutisfalsethen the materializedPublisherwill only support a singleSubscriberand reject any additionalSubscribers. -
def
cancelled[T]: Sink[T, NotUsed]
A
Sinkthat immediately cancels its upstream after materialization. -
def
collection[T, That](implicit cbf: Factory[T, That with Iterable[_]]): Sink[T, Future[That]]
A
Sinkthat keeps on collecting incoming elements until upstream terminates.A
Sinkthat keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].takeor the stricterFlow[T].limit(and their variants) may be used to ensure boundedness. Materializes into aFutureofThat[T]containing all the collected elements.That[T]is limited to the limitations of the CanBuildFrom associated with it. For example,Seqis limited toInt.MaxValueelements. See [The Architecture of Scala 2.13's Collections](https://docs.scala-lang.org/overviews/core/architecture-of-scala-213-collections.html) for more info. This Sink will cancel the stream after having received that many elements.See also Flow.limit, Flow.limitWeighted, Flow.take, Flow.takeWithin, Flow.takeWhile
-
def
combine[T, U](first: Sink[U, _], second: Sink[U, _], rest: Sink[U, _]*)(strategy: (Int) ⇒ Graph[UniformFanOutShape[T, U], NotUsed]): Sink[T, NotUsed]
Combine several sinks with fan-out strategy like
BroadcastorBalanceand returnsSink. -
def
fold[U, T](zero: U)(f: (U, T) ⇒ U): Sink[T, Future[U]]
A
Sinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input.A
Sinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input. The returned scala.concurrent.Future will be completed with value of the final function evaluation when the input stream ends, or completed withFailureif there is a failure signaled in the stream.- See also
-
def
foldAsync[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]
A
Sinkthat will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzerovalue) and the element as input.A
Sinkthat will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzerovalue) and the element as input. The returned scala.concurrent.Future will be completed with value of the final function evaluation when the input stream ends, or completed withFailureif there is a failure signaled in the stream.- See also
-
def
foreach[T](f: (T) ⇒ Unit): Sink[T, Future[Done]]
A
Sinkthat will invoke the given procedure for each received element.A
Sinkthat will invoke the given procedure for each received element. The sink is materialized into a scala.concurrent.Future which will be completed withSuccesswhen reaching the normal end of the stream, or completed withFailureif there is a failure signaled in the stream. -
def
foreachAsync[T](parallelism: Int)(f: (T) ⇒ Future[Unit]): Sink[T, Future[Done]]
A
Sinkthat will invoke the given procedure asynchronously for each received element.A
Sinkthat will invoke the given procedure asynchronously for each received element. The sink is materialized into a scala.concurrent.Future which will be completed withSuccesswhen reaching the normal end of the stream, or completed withFailureif there is a failure signaled in the stream. -
def
fromGraph[T, M](g: Graph[SinkShape[T], M]): Sink[T, M]
A graph with the shape of a sink logically is a sink, this method makes it so also in type.
-
def
fromSubscriber[T](subscriber: Subscriber[T]): Sink[T, NotUsed]
Helper to create Sink from
Subscriber. -
def
head[T]: Sink[T, Future[T]]
A
Sinkthat materializes into aFutureof the first value received.A
Sinkthat materializes into aFutureof the first value received. If the stream completes before signaling at least a single element, the Future will be failed with a NoSuchElementException. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also headOption.
-
def
headOption[T]: Sink[T, Future[Option[T]]]
A
Sinkthat materializes into aFutureof the optional first value received.A
Sinkthat materializes into aFutureof the optional first value received. If the stream completes before signaling at least a single element, the value of the Future will be None. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also head.
-
def
ignore: Sink[Any, Future[Done]]
A
Sinkthat will consume the stream and discard the elements. -
def
last[T]: Sink[T, Future[T]]
A
Sinkthat materializes into aFutureof the last value received.A
Sinkthat materializes into aFutureof the last value received. If the stream completes before signaling at least a single element, the Future will be failed with a NoSuchElementException. If the stream signals an error, the Future will be failed with the stream's exception.See also lastOption, takeLast.
-
def
lastOption[T]: Sink[T, Future[Option[T]]]
A
Sinkthat materializes into aFutureof the optional last value received. -
def
lazyInitAsync[T, M](sinkFactory: () ⇒ Future[Sink[T, M]]): Sink[T, Future[Option[M]]]
Creates a real
Sinkupon receiving the first element.Creates a real
Sinkupon receiving the first element. InternalSinkwill not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Futureis completed withNone. If upstream fails before an element was received,sinkFactorythrows an exception, or materialization of the internal sink fails then theFutureis completed with the exception. Otherwise theFutureis completed with the materialized value of the internal sink. -
def
onComplete[T](callback: (Try[Done]) ⇒ Unit): Sink[T, NotUsed]
A
Sinkthat when the flow is completed, either through a failure or normal completion, apply the provided function with scala.util.Success or scala.util.Failure. -
def
queue[T](): Sink[T, SinkQueueWithCancel[T]]
Creates a
Sinkthat is materialized as an akka.stream.scaladsl.SinkQueue.Creates a
Sinkthat is materialized as an akka.stream.scaladsl.SinkQueue. akka.stream.scaladsl.SinkQueue.pull method is pulling element from the stream and returns.Future[Option[T]]Futurecompletes when element is available.Before calling pull method second time you need to wait until previous Future completes. Pull returns Failed future with IllegalStateException if previous future has not yet completed.
Sinkwill request at most number of elements equal to size ofinputBufferfrom upstream and then stop back pressure. You can configure size of input buffer by using Sink.withAttributes method.For stream completion you need to pull all elements from akka.stream.scaladsl.SinkQueue including last None as completion marker
-
def
reduce[T](f: (T, T) ⇒ T): Sink[T, Future[T]]
A
Sinkthat will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input.A
Sinkthat will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input. The returned scala.concurrent.Future will be completed with value of the final function evaluation when the input stream ends, or completed withFailureif there is a failure signaled in the stream.If the stream is empty (i.e. completes before signalling any elements), the reduce operator will fail its downstream with a NoSuchElementException, which is semantically in-line with that Scala's standard library collections do in such situations.
Adheres to the ActorAttributes.SupervisionStrategy attribute.
-
def
seq[T]: Sink[T, Future[Seq[T]]]
A
Sinkthat keeps on collecting incoming elements until upstream terminates.A
Sinkthat keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].takeor the stricterFlow[T].limit(and their variants) may be used to ensure boundedness. Materializes into aFutureofSeq[T]containing all the collected elements.Seqis limited toInt.MaxValueelements, this Sink will cancel the stream after having received that many elements.See also Flow.limit, Flow.limitWeighted, Flow.take, Flow.takeWithin, Flow.takeWhile
-
def
shape[T](name: String): SinkShape[T]
INTERNAL API
-
def
takeLast[T](n: Int): Sink[T, Future[Seq[T]]]
A
Sinkthat materializes into a aFutureofimmutable.Seq[T]containing the lastncollected elements.A
Sinkthat materializes into a aFutureofimmutable.Seq[T]containing the lastncollected elements.If the stream completes before signaling at least n elements, the
Futurewill complete with all elements seen so far. If the stream never completes, theFuturewill never complete. If there is a failure signaled in the stream theFuturewill be completed with failure.
Deprecated Value Members
-
def
actorSubscriber[T](props: Props): Sink[T, ActorRef]
Creates a
Sinkthat is materialized to an akka.actor.ActorRef which points to an Actor created according to the passed in akka.actor.Props.Creates a
Sinkthat is materialized to an akka.actor.ActorRef which points to an Actor created according to the passed in akka.actor.Props. Actor created by thepropsmust be akka.stream.actor.ActorSubscriber.- Annotations
- @deprecated
- Deprecated
(Since version 2.5.0) Use
akka.stream.stage.GraphStageandfromGraphinstead, it allows for all operations an Actor would and is more type-safe as well as guaranteed to be ReactiveStreams compliant.
-
def
foreachParallel[T](parallelism: Int)(f: (T) ⇒ Unit)(implicit ec: ExecutionContext): Sink[T, Future[Done]]
A
Sinkthat will invoke the given function to each of the elements as they pass in.A
Sinkthat will invoke the given function to each of the elements as they pass in. The sink is materialized into a scala.concurrent.FutureIf
fthrows an exception and the supervision decision is akka.stream.Supervision.Stop theFuturewill be completed with failure.If
fthrows an exception and the supervision decision is akka.stream.Supervision.Resume or akka.stream.Supervision.Restart the element is dropped and the stream continues.See also Flow.mapAsyncUnordered
- Annotations
- @deprecated
- Deprecated
(Since version 2.5.17) Use
foreachAsyncinstead, it allows you to choose how to run the procedure, by calling some other API returning a Future or spawning a new Future.
-
def
lazyInit[T, M](sinkFactory: (T) ⇒ Future[Sink[T, M]], fallback: () ⇒ M): Sink[T, Future[M]]
Creates a real
Sinkupon receiving the first element.Creates a real
Sinkupon receiving the first element. InternalSinkwill not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Futureis completed with the value created by fallback. If upstream fails before an element was received,sinkFactorythrows an exception, or materialization of the internal sink fails then theFutureis completed with the exception. Otherwise theFutureis completed with the materialized value of the internal sink.- Annotations
- @Deprecated @deprecated
- Deprecated
(Since version 2.5.11) Use lazyInitAsync instead. (lazyInitAsync no more needs a fallback function and the materialized value more clearly indicates if the internal sink was materialized or not.)