All Downloads are FREE. Search and download functionalities are using the official Maven repository.

akka.stream.impl.SinkholeSubscriber.scala Maven / Gradle / Ivy

/*
 * Copyright (C) 2014-2020 Lightbend Inc. 
 */

package akka.stream.impl

import akka.Done
import akka.annotation.InternalApi

import scala.concurrent.Promise
import org.reactivestreams.{ Subscriber, Subscription }

/**
 * INTERNAL API
 */
@InternalApi private[akka] final class SinkholeSubscriber[T](whenComplete: Promise[Done]) extends Subscriber[T] {
  private[this] var running: Boolean = false

  override def onSubscribe(sub: Subscription): Unit = {
    ReactiveStreamsCompliance.requireNonNullSubscription(sub)
    if (running) sub.cancel()
    else {
      running = true
      sub.request(Long.MaxValue)
    }
  }

  override def onError(cause: Throwable): Unit = {
    ReactiveStreamsCompliance.requireNonNullException(cause)
    whenComplete.tryFailure(cause)
  }

  override def onComplete(): Unit = whenComplete.trySuccess(Done)

  override def onNext(element: T): Unit = ReactiveStreamsCompliance.requireNonNullElement(element)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy