summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/REST/RESTTaskIdentifier.swift
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-04-29 10:20:55 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-04-29 10:30:26 +0200
commitd652c90c216752ddff6327c47cec99242f12b515 (patch)
treeadfd5f6a753de4e6e7c197faa90402804e9a0006 /ios/MullvadVPN/REST/RESTTaskIdentifier.swift
parent6789b1d4aeab47cb55d385feab6717b928743a01 (diff)
downloadmullvadvpn-d652c90c216752ddff6327c47cec99242f12b515.tar.xz
mullvadvpn-d652c90c216752ddff6327c47cec99242f12b515.zip
REST: break monolith client on smaller proxies
Diffstat (limited to 'ios/MullvadVPN/REST/RESTTaskIdentifier.swift')
-rw-r--r--ios/MullvadVPN/REST/RESTTaskIdentifier.swift25
1 files changed, 25 insertions, 0 deletions
diff --git a/ios/MullvadVPN/REST/RESTTaskIdentifier.swift b/ios/MullvadVPN/REST/RESTTaskIdentifier.swift
new file mode 100644
index 0000000000..412475bcbd
--- /dev/null
+++ b/ios/MullvadVPN/REST/RESTTaskIdentifier.swift
@@ -0,0 +1,25 @@
+//
+// RESTTaskIdentifier.swift
+// MullvadVPN
+//
+// Created by pronebird on 16/04/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+
+extension REST {
+ private static let nslock = NSLock()
+ private static var taskCount: UInt32 = 0
+
+ static func getTaskIdentifier(name: String) -> String {
+ nslock.lock()
+ defer { nslock.unlock() }
+
+ let (partialValue, isOverflow) = taskCount.addingReportingOverflow(1)
+ let nextValue = isOverflow ? 1 : partialValue
+ taskCount = nextValue
+
+ return "\(name).\(nextValue)"
+ }
+}