Skip to content

3.x: Observable.amb marble diagram is a bit incorrect (or maybe it's a bug?) #6995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arkivanov opened this issue May 22, 2020 · 1 comment · Fixed by #7144
Closed

3.x: Observable.amb marble diagram is a bit incorrect (or maybe it's a bug?) #6995

arkivanov opened this issue May 22, 2020 · 1 comment · Fixed by #7144

Comments

@arkivanov
Copy link

Version: 3.0.4

The marble diagram for the Observable.amb operator is as follows:
amb

This means that the second (looser) Observable stays active (subscribed) while the whole amb executes. But in fact all Observables except the first (winner) are being cancelled (disposed).

Please consider the following code snippet:

        Observable
            .amb(
                listOf(
                    Observable
                        .create<Int> {
                            Thread.sleep(500L)
                            it.onNext(1)
                            Thread.sleep(500L)
                            it.onComplete()
                        }
                        .subscribeOn(Schedulers.computation())
                        .doOnNext { Log.v("MyTest", "1: next, $it") }
                        .doOnComplete { Log.v("MyTest", "1: complete") }
                        .doFinally { Log.v("MyTest", "1: finally") },
                    Observable
                        .create<Int> {
                            Thread.sleep(250L)
                            it.onNext(1)
                            Thread.sleep(500L)
                            it.onComplete()
                        }
                        .subscribeOn(Schedulers.computation())
                        .doOnNext { Log.v("MyTest", "2: next, $it") }
                        .doOnComplete { Log.v("MyTest", "2: complete") }
                        .doFinally { Log.v("MyTest", "2: finally") }
                )
            )
            .doOnNext { Log.v("MyTest", "amb: next, $it") }
            .doOnComplete { Log.v("MyTest", "amb: complete") }
            .doFinally { Log.v("MyTest", "amb: finally") }
            .subscribe()

This code produces the following output:

2020-05-22 16:37:01.724 5954-5979/? V/MyTest: 2: next, 1
2020-05-22 16:37:01.724 5954-5979/? V/MyTest: 1: finally
2020-05-22 16:37:01.724 5954-5979/? V/MyTest: amb: next, 1
2020-05-22 16:37:02.224 5954-5979/? V/MyTest: 2: complete
2020-05-22 16:37:02.224 5954-5979/? V/MyTest: amb: complete
2020-05-22 16:37:02.224 5954-5979/? V/MyTest: amb: finally
2020-05-22 16:37:02.224 5954-5979/? V/MyTest: 2: finally

Also it would be nice to describe this behavior explicitly in Java docs.

@akarnokd
Copy link
Member

Some of the older diagrams haven't been updated to include dispose/cancel information. The newer ones are:

image

Also it would be nice to describe this behavior explicitly in Java docs.

PR welcome.

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

Successfully merging a pull request may close this issue.

2 participants