Skip to content
New issue

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

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

Already on GitHub? # to your account

Rxswift的smaple用法 #186

Open
platojobs opened this issue Apr 28, 2022 · 0 comments
Open

Rxswift的smaple用法 #186

platojobs opened this issue Apr 28, 2022 · 0 comments
Labels
MobileDevelopment iOS、安卓、Flutter、go

Comments

@platojobs
Copy link
Owner

platojobs commented Apr 28, 2022

smaple 除了订阅源obs以外,还可以监视另外一个notifier
之间有源就取最新的源发送
两次noti之间如果没有源的话,就不会发送

 func sample(){
        let disbag = DisposeBag()
        let source1 = PublishSubject<Int>()
        let noti1 =  PublishSubject<String>()
        source1.sample(noti1)
            .subscribe(onNext: {
                print($0)
            },onCompleted: {
                print("1===completed")
            }).disposed(by: disbag)
        
        source1.onNext(1)    //1
        noti1.onNext("A")
        source1.onNext(2)  //2
        noti1.onNext("B")
        noti1.onNext("C")
        source1.onNext(3)
        source1.onNext(4)
        noti1.onNext("D")
        source1.onNext(5)
        noti1.onCompleted()
        /*
         1
         2
         4
         5
         */
    }
@platojobs platojobs changed the title 🐶 1 Jul 22, 2022
@platojobs platojobs added the MobileDevelopment iOS、安卓、Flutter、go label Apr 3, 2024
@platojobs platojobs changed the title 1 Rxswift的smaple用法 Apr 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
MobileDevelopment iOS、安卓、Flutter、go
Projects
None yet
Development

No branches or pull requests

1 participant