RxSwift 操作符 (delay & delaySubscription)

delay & delaySubscription

RxSwift:
delay: Returns an observable sequence by the source observable sequence shifted forward in time by a specified delay. Error events from the source observable sequence are not delayed.
delaySubscription: Time shifts the observable sequence by delaying the subscription with the specified relative time duration, using the specified scheduler to run timers.

delay: 设定延迟多少时间发出Observable的每个元素
delaySubscription: 设定多少时间延迟订阅Observable

Observable<Int>.just(1).delay(3, scheduler: MainScheduler.instance)
    .subscribe(onNext: { i in
        print("element1: ", i)
    }).disposed(by: bag)

Observable<Int>.just(2).delaySubscription(3, scheduler: MainScheduler.instance)
    .subscribe(onNext: { i in
        print("element2: ", i)
    }).disposed(by: bag)

延迟3s后输出:
element1: 1
element2: 2

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭