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

阅读更多
个人分类: RxSwift
想对作者说点什么? 我来说一句

RxSwift - API

RxSwift

yangmeng13930719363 yangmeng13930719363

2016-07-14 07:22:43

阅读数:1575

RxSwift 中文文档 epub

2018年04月22日 13.73MB 下载

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

不良信息举报

RxSwift 操作符 (delay & delaySubscription)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭