https://kotlinlang.org logo
#rx
Title
# rx
d

dimsuz

06/25/2020, 5:54 PM
This snippet
Copy code
val subject = PublishSubject.create<Int>()
    Observable.merge(
      Observable.just(1,2,3).doOnSubscribe { println("subscribed to observable") },
      subject.doOnSubscribe { println("subscribed to subject") }
    ).subscribe {
      println("received $it")
    }
prints
Copy code
subscribed to observable
received 1
received 2
received 3
subscribed to subject
Can I somehow ensure that subscrption to merge arguments happens first and only then emittion starts? I.e. I want this to print
Copy code
subscribed to observable
subscribed to subject
received 1, 2, 3
Why: for example I want to post to subject from within
Observable.just(1,3,4).doOnLast { subject.onNext(88) }
ah, or does this happen, because no threading/scheduling is done above? but still I'd like to be sure that subscriptions happen first
OK, answering my own question, looks like this have done it:
Copy code
val subject = PublishSubject.create<Int>()
    subject
      .doOnSubscribe { println("subscribed to subject") }
      .mergeWith(Observable.just(1,3,4).doOnSubscribe { println("subscribed to observable") })
    .subscribe {
      println("received $it")
    }
u

ursus

06/26/2020, 7:30 AM
its blocking code so yea
👌 1
emit your subject after the subscribtion, likr normally on next line
2 Views