summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Operations/InputOperation.swift
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-09-14 13:59:01 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-09-15 10:54:31 +0200
commit76dd2c99bf92d608022efbf05ffcbfebda43e0c1 (patch)
tree8cccb074a033089ac531e425f4a825df62b616c3 /ios/MullvadVPN/Operations/InputOperation.swift
parente553d10b869c46e7ab922b86c32f4bd016e4fdac (diff)
downloadmullvadvpn-76dd2c99bf92d608022efbf05ffcbfebda43e0c1.tar.xz
mullvadvpn-76dd2c99bf92d608022efbf05ffcbfebda43e0c1.zip
Operations: simplify AsyncOperation, remove advanced features
Diffstat (limited to 'ios/MullvadVPN/Operations/InputOperation.swift')
-rw-r--r--ios/MullvadVPN/Operations/InputOperation.swift103
1 files changed, 0 insertions, 103 deletions
diff --git a/ios/MullvadVPN/Operations/InputOperation.swift b/ios/MullvadVPN/Operations/InputOperation.swift
deleted file mode 100644
index a1c9d6931d..0000000000
--- a/ios/MullvadVPN/Operations/InputOperation.swift
+++ /dev/null
@@ -1,103 +0,0 @@
-//
-// InputOperation.swift
-// MullvadVPN
-//
-// Created by pronebird on 06/07/2020.
-// Copyright © 2020 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-
-protocol InputOperation: OperationProtocol {
- associatedtype Input
-
- /// When overriding `input` in Subclasses, make sure to call `operationDidSetInput`
- var input: Input? { get set }
-
- func operationDidSetInput(_ input: Input?)
-}
-
-private var kInputOperationAssociatedValue = 0
-extension InputOperation where Self: OperationSubclassing {
- var input: Input? {
- get {
- return synchronized {
- return AssociatedValue.get(object: self, key: &kInputOperationAssociatedValue)
- }
- }
- set {
- synchronized {
- AssociatedValue.set(object: self, key: &kInputOperationAssociatedValue, value: newValue)
-
- operationDidSetInput(newValue)
- }
- }
- }
-
- func operationDidSetInput(_ input: Input?) {
- // Override in subclasses
- }
-}
-
-extension InputOperation {
-
- @discardableResult func inject<Dependency>(from dependency: Dependency, via block: @escaping (Dependency.Output) -> Input?) -> Self
- where Dependency: OutputOperation
- {
- let observer = OperationBlockObserver<Dependency>(willFinish: { [weak self] (operation) in
- guard let self = self else { return }
-
- if let output = operation.output {
- self.input = block(output)
- }
- })
- dependency.addObserver(observer)
- addDependency(dependency)
-
- return self
- }
-
- @discardableResult func injectResult<Dependency>(from dependency: Dependency) -> Self
- where Dependency: OutputOperation, Dependency.Output == Input?
- {
- return self.inject(from: dependency, via: { $0 })
- }
-
- /// Inject input from operation that outputs `Result<Input, Failure>`
- @discardableResult func injectResult<Dependency, Failure>(from dependency: Dependency) -> Self
- where Dependency: OutputOperation, Failure: Error, Dependency.Output == Result<Input, Failure>
- {
- return self.inject(from: dependency) { (output) -> Input? in
- switch output {
- case .success(let value):
- return value
- case .failure:
- return nil
- }
- }
- }
-
- /// Inject input from operation that outputs `Result<Input, Never>`
- @discardableResult func injectResult<Dependency>(from dependency: Dependency) -> Self
- where Dependency: OutputOperation, Dependency.Output == Result<Input, Never>
- {
- return self.inject(from: dependency) { (output) -> Input? in
- switch output {
- case .success(let value):
- return value
- }
- }
- }
-
- /// Inject input from operation that outputs `Result<Input?, Never>`
- @discardableResult func injectResult<Dependency>(from dependency: Dependency) -> Self
- where Dependency: OutputOperation, Dependency.Output == Result<Input?, Never>
- {
- return self.inject(from: dependency) { (output) -> Input? in
- switch output {
- case .success(let value):
- return value
- }
- }
- }
-}