2
votes

I have two subscribers for a BehaviorRelay observable type named profileUpdates.

Publishing my data through,

Observables.shared.profileUpdates.accept(data)

Subscribing in two points in code (Suppose A and B) through,

Observables.shared.profileUpdates.subscribe(onNext: { } )

Now, can I define the sequence I would be able to get the subscribed data or it is strictly dependant on the library?

For example, in point A after point B, or vice versa.

1

1 Answers

3
votes

There is no documented contract that guarantees the order that subscribes will be called in. They will be called sequentially, but the order is undefined.

It would be best to use the do operator for this:

profileUpdates
    .do(onNext: { value in
        // perform side effect
    })
    .subscribe(onNext: { value in
        // perform other side effect
    })
    .disposed(by: disposeBag)

However, excessive use of the do operator (and Relays for that matter) are a code smell and imply you are still thinking imperatively.