+str - #17662 - Changes Sink.ignore to return a Future[Unit]

This commit is contained in:
Viktor Klang 2015-06-05 18:26:32 +02:00
parent 8527e0347e
commit 3dd40fc18c
6 changed files with 15 additions and 13 deletions

View file

@ -106,8 +106,8 @@ class TwitterStreamQuickstartDocSpec extends AkkaSpec {
} }
"simple broadcast" in { "simple broadcast" in {
val writeAuthors: Sink[Author, Unit] = Sink.ignore val writeAuthors: Sink[Author, Future[Unit]] = Sink.ignore
val writeHashtags: Sink[Hashtag, Unit] = Sink.ignore val writeHashtags: Sink[Hashtag, Future[Unit]] = Sink.ignore
// format: OFF // format: OFF
//#flow-graph-broadcast //#flow-graph-broadcast

View file

@ -4,12 +4,13 @@
package akka.stream.tck package akka.stream.tck
import akka.stream.impl.BlackholeSubscriber import akka.stream.impl.BlackholeSubscriber
import scala.concurrent.Promise
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber import org.reactivestreams.Subscriber
class BlackholeSubscriberTest extends AkkaSubscriberBlackboxVerification[Int] { class BlackholeSubscriberTest extends AkkaSubscriberBlackboxVerification[Int] {
override def createSubscriber(): Subscriber[Int] = new BlackholeSubscriber[Int](2) override def createSubscriber(): Subscriber[Int] = new BlackholeSubscriber[Int](2, Promise[Unit]())
override def createElement(element: Int): Int = element override def createElement(element: Int): Int = element
} }

View file

@ -4,14 +4,14 @@
package akka.stream.impl package akka.stream.impl
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.Promise
import org.reactivestreams.{ Subscriber, Subscription } import org.reactivestreams.{ Subscriber, Subscription }
/** /**
* INTERNAL API * INTERNAL API
*/ */
private[akka] class BlackholeSubscriber[T](highWatermark: Int) extends Subscriber[T] { private[akka] class BlackholeSubscriber[T](highWatermark: Int, onComplete: Promise[Unit]) extends Subscriber[T] {
private val lowWatermark = Math.max(1, highWatermark / 2) private val lowWatermark = Math.max(1, highWatermark / 2)
private var requested = 0L private var requested = 0L
@ -26,10 +26,11 @@ private[akka] class BlackholeSubscriber[T](highWatermark: Int) extends Subscribe
override def onError(cause: Throwable): Unit = { override def onError(cause: Throwable): Unit = {
ReactiveStreamsCompliance.requireNonNullException(cause) ReactiveStreamsCompliance.requireNonNullException(cause)
onComplete.tryFailure(cause)
() ()
} }
override def onComplete(): Unit = () override def onComplete(): Unit = onComplete.trySuccess(())
override def onNext(element: T): Unit = { override def onNext(element: T): Unit = {
ReactiveStreamsCompliance.requireNonNullElement(element) ReactiveStreamsCompliance.requireNonNullElement(element)

View file

@ -150,15 +150,15 @@ private[akka] class HeadSink[In](val attributes: OperationAttributes, shape: Sin
* Attaches a subscriber to this stream which will just discard all received * Attaches a subscriber to this stream which will just discard all received
* elements. * elements.
*/ */
private[akka] final class BlackholeSink(val attributes: OperationAttributes, shape: SinkShape[Any]) extends SinkModule[Any, Unit](shape) { private[akka] final class BlackholeSink(val attributes: OperationAttributes, shape: SinkShape[Any]) extends SinkModule[Any, Future[Unit]](shape) {
override def create(context: MaterializationContext) = { override def create(context: MaterializationContext) = {
val effectiveSettings = ActorFlowMaterializer.downcast(context.materializer) val effectiveSettings = ActorFlowMaterializer.downcast(context.materializer).effectiveSettings(context.effectiveAttributes)
.effectiveSettings(context.effectiveAttributes) val p = Promise[Unit]()
(new BlackholeSubscriber[Any](effectiveSettings.maxInputBufferSize), ()) (new BlackholeSubscriber[Any](effectiveSettings.maxInputBufferSize, p), p.future)
} }
override protected def newInstance(shape: SinkShape[Any]): SinkModule[Any, Unit] = new BlackholeSink(attributes, shape) override protected def newInstance(shape: SinkShape[Any]): SinkModule[Any, Future[Unit]] = new BlackholeSink(attributes, shape)
override def withAttributes(attr: OperationAttributes): Module = new BlackholeSink(attr, amendShape(attr)) override def withAttributes(attr: OperationAttributes): Module = new BlackholeSink(attr, amendShape(attr))
} }

View file

@ -47,7 +47,7 @@ object Sink {
/** /**
* A `Sink` that will consume the stream and discard the elements. * A `Sink` that will consume the stream and discard the elements.
*/ */
def ignore[T](): Sink[T, Unit] = def ignore[T](): Sink[T, Future[Unit]] =
new Sink(scaladsl.Sink.ignore) new Sink(scaladsl.Sink.ignore)
/** /**

View file

@ -95,7 +95,7 @@ object Sink extends SinkApply {
/** /**
* A `Sink` that will consume the stream and discard the elements. * A `Sink` that will consume the stream and discard the elements.
*/ */
def ignore: Sink[Any, Unit] = def ignore: Sink[Any, Future[Unit]] =
new Sink(new BlackholeSink(DefaultAttributes.ignoreSink, shape("BlackholeSink"))) new Sink(new BlackholeSink(DefaultAttributes.ignoreSink, shape("BlackholeSink")))
/** /**