diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-09-14 11:04:51 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-09-15 10:58:44 +0200 |
| commit | d4b16e147ea15670836902f6e222067bc0add324 (patch) | |
| tree | 6aac6706e1943587b03483ff2bdf07f40e347475 /ios | |
| parent | 3aa35051d68b09c50fa1fcbcba6c2410dcb0d894 (diff) | |
| download | mullvadvpn-d4b16e147ea15670836902f6e222067bc0add324.tar.xz mullvadvpn-d4b16e147ea15670836902f6e222067bc0add324.zip | |
Promise: avoid using observe() in onSuccess and onFailure calls
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/Promise/Promise+Result.swift | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/ios/MullvadVPN/Promise/Promise+Result.swift b/ios/MullvadVPN/Promise/Promise+Result.swift index 94dd511227..b09595f707 100644 --- a/ios/MullvadVPN/Promise/Promise+Result.swift +++ b/ios/MullvadVPN/Promise/Promise+Result.swift @@ -51,21 +51,19 @@ extension Promise where Value: AnyResult { } } - /// Perform actiion on success. - func onSuccess(_ onResolve: @escaping (Success) -> Void) -> Self { - return observe { completion in - if case .success(let value) = completion.unwrappedValue?.asConcreteType() { - onResolve(value) - } + /// Perform action on success. + func onSuccess(_ onResolve: @escaping (Success) -> Void) -> Result<Success, Failure>.Promise { + return map { value -> Success in + onResolve(value) + return value } } /// Perform action on failure. - func onFailure(_ onResolve: @escaping (Failure) -> Void) -> Self { - return observe { completion in - if case .failure(let error) = completion.unwrappedValue?.asConcreteType() { - onResolve(error) - } + func onFailure(_ onResolve: @escaping (Failure) -> Void) -> Result<Success, Failure>.Promise { + return mapError { error -> Failure in + onResolve(error) + return error } } |
