             failure(ImageControllerError.invalidOrEmptyURL)
             return
         }
-        let completionKey = identifierForURL(url)
+        let identifier = identifierForURL(url)
         let completion = ImageControllerDataCompletion(success: success, failure: failure)
-        guard dataCompletionManager.add(completion, forKey: completionKey) else {
+        guard dataCompletionManager.add(completion, forIdentifier: identifier) else {
             return
         }
         let schemedURL = (url as NSURL).wmf_urlByPrependingSchemeIfSchemeless() as URL
         let task = session.dataTask(with: schemedURL) { (data, response, error) in
-            self.dataCompletionManager.complete(forKey: completionKey, enumerator: { (completion) in
+            self.dataCompletionManager.complete(identifier, enumerator: { (completion) in
                 guard let data = data, let response = response else {
                     completion.failure(error ?? ImageControllerError.invalidResponse)
                     return


fileprivate class ImageControllerCompletionManager<T> {
    var completions: [String: [T]] = [:]
    var tasks: [String: URLSessionTask] = [:]
    let queue = DispatchQueue(label: "ImageControllerCompletionManager-" + UUID().uuidString)
    
    func add(_ completion: T, forKey key: String) -> Bool {
        return queue.sync {
            var completionsForKey = completions[key] ?? []
            let isFirst = completionsForKey.count == 0
            completionsForKey.append(completion)
            completions[key] = completionsForKey
            return isFirst
        }
    }
    
    func add(_ task: URLSessionTask, forKey key: String) {
        queue.sync {
            tasks[key] = task
        }
    }
    
    func cancel(_ key: String) {
        queue.async {
            guard let task = self.tasks[key] else {
                return
            }
            task.cancel()
        }
    }
    
    func complete(forKey key: String, enumerator: @escaping (T) -> Void) {
        queue.async {
            guard let completionsForKey = self.completions[key] else {
                return
            }
            for completion in completionsForKey {
                enumerator(completion)
            }
            self.completions.removeValue(forKey: key)
            self.tasks.removeValue(forKey: key)
        }
    }
}


            })
        }
        task.priority = priority
        dataCompletionManager.add(task, forIdentifier: identifier)
        task.resume()
    }
    
