+str - #17662 - Changes Sink.ignore to return a Future[Unit]
This commit is contained in:
parent
8527e0347e
commit
3dd40fc18c
6 changed files with 15 additions and 13 deletions
|
|
@ -106,8 +106,8 @@ class TwitterStreamQuickstartDocSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"simple broadcast" in {
|
||||
val writeAuthors: Sink[Author, Unit] = Sink.ignore
|
||||
val writeHashtags: Sink[Hashtag, Unit] = Sink.ignore
|
||||
val writeAuthors: Sink[Author, Future[Unit]] = Sink.ignore
|
||||
val writeHashtags: Sink[Hashtag, Future[Unit]] = Sink.ignore
|
||||
|
||||
// format: OFF
|
||||
//#flow-graph-broadcast
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
package akka.stream.tck
|
||||
|
||||
import akka.stream.impl.BlackholeSubscriber
|
||||
import scala.concurrent.Promise
|
||||
import org.reactivestreams.Publisher
|
||||
import org.reactivestreams.Subscriber
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
package akka.stream.impl
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
import scala.concurrent.Promise
|
||||
import org.reactivestreams.{ Subscriber, Subscription }
|
||||
|
||||
/**
|
||||
* 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 var requested = 0L
|
||||
|
|
@ -26,10 +26,11 @@ private[akka] class BlackholeSubscriber[T](highWatermark: Int) extends Subscribe
|
|||
|
||||
override def onError(cause: Throwable): Unit = {
|
||||
ReactiveStreamsCompliance.requireNonNullException(cause)
|
||||
onComplete.tryFailure(cause)
|
||||
()
|
||||
}
|
||||
|
||||
override def onComplete(): Unit = ()
|
||||
override def onComplete(): Unit = onComplete.trySuccess(())
|
||||
|
||||
override def onNext(element: T): Unit = {
|
||||
ReactiveStreamsCompliance.requireNonNullElement(element)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* 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) = {
|
||||
val effectiveSettings = ActorFlowMaterializer.downcast(context.materializer)
|
||||
.effectiveSettings(context.effectiveAttributes)
|
||||
(new BlackholeSubscriber[Any](effectiveSettings.maxInputBufferSize), ())
|
||||
val effectiveSettings = ActorFlowMaterializer.downcast(context.materializer).effectiveSettings(context.effectiveAttributes)
|
||||
val p = Promise[Unit]()
|
||||
(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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ object Sink {
|
|||
/**
|
||||
* 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)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ object Sink extends SinkApply {
|
|||
/**
|
||||
* 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")))
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue