How do I leverage ReactiveX to execute async calls in sequence? I.e., execute a second call after first one has finished.
More specifically, I'm working with RxSwift in iOS, and the asyncs I want to chain together are UIView
animations (instead of calling the second animation inside the completion
block of the first one).
I know I have other options like Easy Animation, but I'd like to leverage Rx, since I'm already using it for streams.
Also, one solution would be (for 3 chained animations):
_ = UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformMakeScale(1.8, 1.8)
})
.flatMap({ _ in
return UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformMakeScale(0.8, 0.8)
})
})
.flatMap({ _ in
return UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformIdentity
})
})
.subscribeNext({ _ in })
But I'm looking for something more elegant, the right way of doing it with Rx.