class AAAViewController : UIViewController { public let a: PublishRelay<Void> = .init() public let disposeBag = DisposeBag() func viewDidLoad() { a.flatMapLatest { uself.request() } .subscribe() .disposed(by: disposeBag) } func onButtonClick() { a.accept(()) } private func request() -> Observable<Int> { return Observable<Int>.just(3) .delay(2.0, scheduler: MainScheduler.instance) .do(onSubscribe: { print("subscribe") }, onDispose: { print("dispose") }) } }