I asked this question on coursera forum (class.coursera.org/reactive-001/forum/thread?thread_id=1858) as @MarkLister suggested and got an answer.
It's seems to be a bug in version 0.15.1: github.com/Netflix/RxJava/issues/559
質問
I'm trying to learn RxScala. I'm using Observable.interval(1 second).buffer(10 seconds)
and doing a subscription to print the values, but can't get unsubscribe right. After I unsubscribe a subscription it keeps running, but with empty result.
My code:
import scala.language.postfixOps
import scala.concurrent.duration.DurationLong
import scala.concurrent.duration.DurationInt
import scala.concurrent.duration.Duration
import rx.lang.scala._
val o = Observable.interval(1 second).buffer(10 seconds)
val s = o.subscribe(
{ n => println("buffer --> " + n) },
e => { e.printStackTrace() },
() => { println("Completed!") })
It prints well the results:
buffer --> Buffer(0, 1, 2, 3, 4, 5, 6, 7, 8)
buffer --> Buffer(9, 10, 11, 12, 13, 14, 15, 16, 17, 18)
buffer --> Buffer(19, 20, 21, 22, 23, 24, 25, 26, 27, 28)
buffer --> Buffer(29, 30, 31, 32, 33, 34, 35, 36, 37, 38)
After some time I unsubscribe:
s.unsubscribe
And I still get the prints, but with empty Buffers:
buffer --> Buffer()
I think that means my subscription is still running, but receiving empty Buffers, how can I stop my subscription?
解決
I asked this question on coursera forum (class.coursera.org/reactive-001/forum/thread?thread_id=1858) as @MarkLister suggested and got an answer.
It's seems to be a bug in version 0.15.1: github.com/Netflix/RxJava/issues/559