Skip to content

2.x: Possible bug while reusing replay().refCount()  #6471

Description

@Rajin9601

Version : 2.2.8

Code (in Kotlin, in Android)

val tmp = Observable.just(Unit)
    .flatMap {
        Observable.just(1, 2).delay(1000, TimeUnit.MILLISECONDS)
    }.doOnNext { Log.i("TEST", "onNext: " + it.toString())}
    .replay(1).refCount()

tmp.subscribeBy { // subscription 1
    Log.i("TEST", "sub1 : $it")
}

Completable.complete()
    .delay(5000, TimeUnit.MILLISECONDS)
    .subscribeBy {
        tmp.subscribeBy { // subscription 2
            Log.i("TEST", "sub2 : $it")
        }
        tmp.subscribeBy { // subscription 3
            Log.i("TEST", "sub3 : $it")
        }
    }

Log

2019-04-30 16:52:38.364 31138-31449/com.app.sample I/TEST: onNext: 1
2019-04-30 16:52:38.364 31138-31449/com.app.sample I/TEST: sub1 : 1
2019-04-30 16:52:38.364 31138-31449/com.app.sample I/TEST: onNext: 2
2019-04-30 16:52:38.364 31138-31449/com.app.sample I/TEST: sub1 : 2

2019-04-30 16:52:42.367 31138-31450/com.app.sample I/TEST: sub2 : 2

2019-04-30 16:52:43.376 31138-31510/com.app.sample I/TEST: onNext: 1
2019-04-30 16:52:43.377 31138-31510/com.app.sample I/TEST: sub3 : 1
2019-04-30 16:52:43.377 31138-31510/com.app.sample I/TEST: onNext: 2
2019-04-30 16:52:43.377 31138-31510/com.app.sample I/TEST: sub3 : 2

Explanation

At the time of subscription 2, I expected connectable observable from replay(1) to start over and emit 1 and 2, just like subscription 3. However, subscription 2 only emits 2.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions