Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions MapboxSceneKit/MapboxImageAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public final class MapboxImageAPI: NSObject {

let group = DispatchGroup()
let groupID = UUID()
pendingFetches[groupID] = [UUID]()
pendingFetchesDispatchQueue.sync(flags: .barrier) { [weak self] in
guard let self = self else { return }
self.pendingFetches[groupID] = [UUID]()
}

var completed: Int = 0
let total = bounding.xs.count * bounding.ys.count
Expand Down Expand Up @@ -196,7 +199,10 @@ public final class MapboxImageAPI: NSObject {

let group = DispatchGroup()
let groupID = UUID()
pendingFetches[groupID] = [UUID]()
pendingFetchesDispatchQueue.sync(flags: .barrier) { [weak self] in
guard let self = self else { return }
pendingFetches[groupID] = [UUID]()
}

var completed: Int = 0
let total = bounding.xs.count * bounding.ys.count
Expand Down Expand Up @@ -234,9 +240,13 @@ public final class MapboxImageAPI: NSObject {
}
}
}

pendingFetchesDispatchQueue.sync(flags: .barrier) { [weak self] in
guard let self = self else { return }
self.pendingFetches.removeValue(forKey: groupID)
}

group.notify(queue: DispatchQueue.main) {
self.pendingFetches.removeValue(forKey: groupID)
completion(error == nil ? imageBuilder.makeImage() : nil, error?.toNSError())
}

Expand All @@ -254,7 +264,10 @@ public final class MapboxImageAPI: NSObject {
for task in tasks {
httpAPI.cancelRequestWithID(task)
}
pendingFetches.removeValue(forKey: groupID)
pendingFetchesDispatchQueue.sync(flags: .barrier) { [weak self] in
guard let self = self else { return }
self.pendingFetches.removeValue(forKey: groupID)
}
}

//MARK: - Helpers
Expand Down