LoginSignup
0
0

More than 5 years have passed since last update.

RxJavaでPublishSubjectをsubscribeした時にonErrorが呼ばれるとそれ以降動かなくなる

Posted at

サンプルコード

        subject.subscribe ({ number ->
            println(number.toString())

            if (number == 3) throw RuntimeException()
        }, {
            println("onError")
        }, {
            println("onComplete")
        })

        subject.onNext(1)
        subject.onNext(2)
        subject.onNext(3)
        subject.onNext(4)
        subject.onNext(5)

実行結果

1
2
3
onError

4と5が表示されない。

所感

onErrorに入った時にちゃんと気がつけないと、何故かいきなり動かなくなってる。。。!
という辛みがあるので注意。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0