Execute code regardless of outcome with `ensure` and `finally`
masterTo perform cleanup or reset state (like hiding a loading spinner) regardless of whether a chain succeeds or fails, use these handlers:
ensure: This handler is always called, whether the chain succeeds or fails. It is part of the chain and can be followed by other handlers.finally: A variant ofensurethat terminates the promise chain and does not return a value.
firstly {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
return login()
}.then {
fetch(avatar: $0.user)
}.done {
self.imageView = $0
}.ensure {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch {
//…
}