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

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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试