1

When binding two specific operations to a button tap, does execution order follow binding order?

For example, in the following code, is there a way to tell what gets executed first?

self.resetButton.rx.tap.bind(to: viewModel!.resetPasswordButtonObserver).disposed(by: disposeBag)

self.resetButton.rx.tap.bind {[weak self] in
    self?.loader.lock()
}.disposed(by: disposeBag)

In my code, the viewModel calls an API and executes the reset operation before the self?.loader.lock() block is executed, which may cause problems for really fast connections.

bedranfleck
  • 165
  • 2
  • 8

1 Answers1

1

Unless you change the thread that the code executes on, it will execute in the order you wrote it.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • So the execution order obeys the binding order unless the operations are being executed concurrently? For some reason I thought all bindings were executed simultaneously. Thanks for your answer, I will mark it as accepted. – bedranfleck Jun 14 '19 at 13:53
  • 1
    RxSwift is synchronous by default. All work is executed at the moment the subscribe is called. – Daniel T. Jun 14 '19 at 23:53