Skip to content

Commit a7ccf17

Browse files
evil159github-actions[bot]
authored andcommitted
[maps-ios] use DI-ed main queue instead of the singleton (#9080)
This PR addresses `testPartialUpdateCancellableIsDeallocatedWhenUpdateIsComplete()` by making sure `StyleSourceManager` uses main queue instance passed as a init dependency instead of the global singleton. cc @mapbox/maps-ios GitOrigin-RevId: 8a1bb87bc83086e69061c7565e88c0a291b21cc5
1 parent b848a98 commit a7ccf17

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Sources/MapboxMaps/Style/StyleSourceManager.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
110110
let identifier = UUID()
111111
let item = DispatchWorkItem { [weak self] in
112112
guard let self else { return }
113+
defer {
114+
self.mainQueue.async { [weak self] in
115+
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
116+
}
117+
}
113118
do {
114119
try handleExpected {
115120
return self.styleManager.addGeoJSONSourceFeatures(forSourceId: sourceId,
@@ -120,9 +125,6 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
120125
Log.error("Failed to add features for source with id: \(sourceId), dataId: \(dataId ?? ""), error: \(error)")
121126
}
122127
}
123-
item.notify(queue: .main) { [weak self] in
124-
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
125-
}
126128
workItemTracker.addPartialUpdateCancelable(AnyCancelable(item.cancel), for: sourceId, uuid: identifier)
127129
backgroundQueue.async(execute: item)
128130
}
@@ -167,6 +169,11 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
167169
let identifier = UUID()
168170
let item = DispatchWorkItem { [weak self] in
169171
guard let self else { return }
172+
defer {
173+
self.mainQueue.async { [weak self] in
174+
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
175+
}
176+
}
170177
do {
171178
try handleExpected {
172179
return self.styleManager.updateGeoJSONSourceFeatures(forSourceId: sourceId,
@@ -177,9 +184,6 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
177184
Log.error("Failed to update features for source with id: \(sourceId), dataId: \(dataId ?? ""), error: \(error)")
178185
}
179186
}
180-
item.notify(queue: .main) { [weak self] in
181-
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
182-
}
183187

184188
workItemTracker.addPartialUpdateCancelable(AnyCancelable(item.cancel), for: sourceId, uuid: identifier)
185189
backgroundQueue.async(execute: item)
@@ -189,6 +193,11 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
189193
let identifier = UUID()
190194
let item = DispatchWorkItem { [weak self] in
191195
guard let self else { return }
196+
defer {
197+
self.mainQueue.async { [weak self] in
198+
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
199+
}
200+
}
192201
do {
193202
try handleExpected {
194203
return self.styleManager.removeGeoJSONSourceFeatures(forSourceId: sourceId,
@@ -199,9 +208,6 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
199208
Log.error("Failed to remove features for source with id: \(sourceId), dataId: \(dataId ?? ""), error: \(error)")
200209
}
201210
}
202-
item.notify(queue: .main) { [weak self] in
203-
self?.workItemTracker.removePartialUpdateCancelable(for: sourceId, uuid: identifier)
204-
}
205211

206212
workItemTracker.addPartialUpdateCancelable(AnyCancelable(item.cancel), for: sourceId, uuid: identifier)
207213
backgroundQueue.async(execute: item)

Tests/MapboxMapsTests/Foundation/Style/StyleSourceManagerTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ final class StyleSourceManagerTests: XCTestCase {
565565
let dummyQueue = DispatchQueue(label: "Dummy queue", qos: .userInitiated)
566566
let sourceId = "sourceId"
567567

568+
// Make mainQueue execute cleanup blocks synchronously
569+
mainQueue.asyncClosureStub.defaultSideEffect = { $0.parameters.work() }
570+
568571
sourceManager.addGeoJSONSourceFeatures(forSourceId: sourceId, features: [], dataId: nil)
569572
sourceManager.updateGeoJSONSourceFeatures(forSourceId: sourceId, features: [], dataId: nil)
570573
sourceManager.removeGeoJSONSourceFeatures(forSourceId: sourceId, featureIds: [], dataId: nil)

0 commit comments

Comments
 (0)