Skip to content

pairwise broke BehaviorRelay #274

@davidfuzju

Description

@davidfuzju

hi, I use pairwise with BehaviorRelay to listener the userInfo's changes, by compared with old and new, then make some animation.

Expected: use pairwise with behaviorRelay, when there is a new subscription, behaviorRelay will emit latest element and with the power of pairwise, subscription will get a old and new tuple
Actual: use pairwise with behaviorRelay, behaviorRelay will stop emit latest element for new subscription

Anyone helps?

// use pairwise
UserDetailManager.shared
.userDetailUpdateRelay
.pairwise()
.subscribe(onNext: { [weak self] (old, new) in 
       // BehaviorRelay not emit latest element for subscription
       // thought I read the doc that pairwise will not emit anything until the source observable emits at least 2 elements
       // however, after behaviorRelay has emit > 2 elements, BehaviorRelay will not emit any element for the new subscription
})
 .disposed(by: rx.disposeBag)

// not use pairwise
UserDetailManager.shared
.userDetailUpdateRelay
.subscribe(onNext: { [weak self] data in 
        // BehaviorRelay will emit latest element for subscription
        // for example, A UIView as a observer to subscribe this relay will get the latest element to show something for user
})
 .disposed(by: rx.disposeBag)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions