summaryrefslogtreecommitdiffhomepage
path: root/ios/Operations
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-11-24 16:49:48 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-11-28 10:39:08 +0100
commit35452115580bbb484b865ef0956a80f4a4f96ca8 (patch)
treeb0f78b78358c42180c24a131c3c2828267138fe1 /ios/Operations
parent48fd1e95e2b4fa862b06b7b3eb4c0ff03436ac28 (diff)
downloadmullvadvpn-35452115580bbb484b865ef0956a80f4a4f96ca8.tar.xz
mullvadvpn-35452115580bbb484b865ef0956a80f4a4f96ca8.zip
Add OperationCompletion.get() helper
Diffstat (limited to 'ios/Operations')
-rw-r--r--ios/Operations/OperationCompletion.swift14
1 files changed, 14 insertions, 0 deletions
diff --git a/ios/Operations/OperationCompletion.swift b/ios/Operations/OperationCompletion.swift
index 0e004bfe50..49a34e0884 100644
--- a/ios/Operations/OperationCompletion.swift
+++ b/ios/Operations/OperationCompletion.swift
@@ -65,6 +65,14 @@ public enum OperationCompletion<Success, Failure: Error> {
}
}
+ public func get() throws -> Success {
+ if let result = result {
+ return try result.get()
+ } else {
+ throw OperationCancellationError()
+ }
+ }
+
public func map<NewSuccess>(_ block: (Success) -> NewSuccess)
-> OperationCompletion<NewSuccess, Failure>
{
@@ -143,3 +151,9 @@ public enum OperationCompletion<Success, Failure: Error> {
return mapError { $0 }
}
}
+
+public struct OperationCancellationError: LocalizedError {
+ public var errorDescription: String? {
+ return "Operation was cancelled."
+ }
+}