Skip to content

Commit 5eae19c

Browse files
authored
Fix lock on offline start (#555)
1 parent c7d8461 commit 5eae19c

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

LeanplumSDK/LeanplumSDK/ClassesSwift/Migration/MigrationManager.swift

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import Foundation
4242
}
4343
}
4444

45-
private let lock = NSLock()
46-
4745
@objc public func launchWrapper() {
4846
if migrationState.useCleverTap, wrapper == nil {
4947
guard let id = accountId, let token = accountToken, let accountRegion = regionCode else {
@@ -118,44 +116,19 @@ import Foundation
118116
}
119117
}
120118

121-
122-
// onMigrationStateLoaded
123-
124-
@objc public func fetchMigrationState(_ completion: @escaping ()->()) {
119+
@objc public func fetchMigrationState(_ completion: @escaping () -> ()) {
125120
if migrationState != .undefined {
126121
launchWrapper()
127122
completion()
128123
return
129124
}
130125

131-
fetchMigrationStateClosures.append(completion)
132-
}
133-
134-
var fetchMigrationStateClosures:[(() -> Void)] = [] {
135-
willSet {
136-
lock.lock()
137-
}
138-
didSet {
139-
defer {
140-
lock.unlock()
141-
}
142-
if oldValue.isEmpty && fetchMigrationStateClosures.count > 0 {
143-
fetchMigrationStateAsync { [weak self] in
144-
self?.triggerFetchMigrationState()
145-
}
146-
}
147-
}
148-
}
149-
150-
private func triggerFetchMigrationState() {
151-
let closures = fetchMigrationStateClosures
152-
fetchMigrationStateClosures = []
153-
for closure in closures {
154-
closure()
126+
fetchMigrationStateAsync {
127+
completion()
155128
}
156129
}
157130

158-
func fetchMigrationStateAsync(completion: @escaping ()->()) {
131+
func fetchMigrationStateAsync(completion: @escaping () -> ()) {
159132
let request = LPRequestFactory.getMigrateState()
160133
request.requestType = .Immediate
161134
request.onResponse { operation, response in

0 commit comments

Comments
 (0)