diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-09-14 13:59:01 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-09-15 10:54:31 +0200 |
| commit | 76dd2c99bf92d608022efbf05ffcbfebda43e0c1 (patch) | |
| tree | 8cccb074a033089ac531e425f4a825df62b616c3 /ios/MullvadVPN/Operations/TransformOperationObserver.swift | |
| parent | e553d10b869c46e7ab922b86c32f4bd016e4fdac (diff) | |
| download | mullvadvpn-76dd2c99bf92d608022efbf05ffcbfebda43e0c1.tar.xz mullvadvpn-76dd2c99bf92d608022efbf05ffcbfebda43e0c1.zip | |
Operations: simplify AsyncOperation, remove advanced features
Diffstat (limited to 'ios/MullvadVPN/Operations/TransformOperationObserver.swift')
| -rw-r--r-- | ios/MullvadVPN/Operations/TransformOperationObserver.swift | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/ios/MullvadVPN/Operations/TransformOperationObserver.swift b/ios/MullvadVPN/Operations/TransformOperationObserver.swift deleted file mode 100644 index e6ed695e0b..0000000000 --- a/ios/MullvadVPN/Operations/TransformOperationObserver.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// TransformOperationObserver.swift -// MullvadVPN -// -// Created by pronebird on 06/07/2020. -// Copyright © 2020 Mullvad VPN AB. All rights reserved. -// - -import Foundation - -/// A private type erasing observer that type casts the input operation type to the expected -/// operation type before calling the wrapped observer -class TransformOperationObserver<S: OperationProtocol>: OperationObserver { - private let willExecute: (S) -> Void - private let willFinish: (S) -> Void - private let didFinish: (S) -> Void - - init<T: OperationObserver>(_ observer: T) { - willExecute = Self.wrap(observer.operationWillExecute) - willFinish = Self.wrap(observer.operationWillFinish) - didFinish = Self.wrap(observer.operationDidFinish) - } - - func operationWillExecute(_ operation: S) { - willExecute(operation) - } - - func operationWillFinish(_ operation: S) { - willFinish(operation) - } - - func operationDidFinish(_ operation: S) { - didFinish(operation) - } - - private class func wrap<U>(_ body: @escaping (U) -> Void) -> (S) -> Void { - return { (operation: S) in - if let transformed = operation as? U { - body(transformed) - } else { - fatalError("\(Self.self) failed to cast \(S.self) to \(U.self)") - } - } - } -} |
