Skip to content

Commit

Permalink
Merge pull request #1641 from jbripley/rxscala-onstart-recursive
Browse files Browse the repository at this point in the history
RxScala: Fix infinite recursive onStart call in Subscriber
  • Loading branch information
benjchristensen committed Aug 30, 2014
2 parents c6a23fa + 632290d commit 5ee6073
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ trait Subscriber[-T] extends Observer[T] with Subscription {
self =>

private [scala] val asJavaSubscriber: rx.Subscriber[_ >: T] = new rx.Subscriber[T] with SubscriberAdapter[T] {
override def onStart(): Unit = self.onStart()
override def onNext(value: T): Unit = self.onNext(value)
override def onError(error: Throwable): Unit = self.onError(error)
override def onCompleted(): Unit = self.onCompleted()
Expand Down Expand Up @@ -36,7 +35,7 @@ trait Subscriber[-T] extends Observer[T] with Subscription {
}

override final def isUnsubscribed: Boolean = {
asJavaSubscriber.isUnsubscribed()
asJavaSubscriber.isUnsubscribed
}

def onStart(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package rx.lang.scala
import org.junit.Test
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Assert.assertFalse
import org.junit.Assert.assertEquals
import org.scalatest.junit.JUnitSuite

class SubscriberTests extends JUnitSuite {
Expand Down Expand Up @@ -57,4 +59,27 @@ class SubscriberTests extends JUnitSuite {
assertTrue(subscription.isUnsubscribed)
}

@Test def testNewSubscriber(): Unit = {
var didComplete = false
var didError = false
var onNextValue = 0

Observable.just(1).subscribe(new Subscriber[Int] {
override def onCompleted(): Unit = {
didComplete = true
}

override def onError(e: Throwable): Unit = {
didError = true
}

override def onNext(v: Int): Unit = {
onNextValue = v
}
})

assertTrue("Subscriber called onCompleted", didComplete)
assertFalse("Subscriber did not call onError", didError)
assertEquals(1, onNextValue)
}
}

0 comments on commit 5ee6073

Please sign in to comment.