#4090 - Use a dedicated dispatch queue for process

This commit is contained in:
Gil Eluard
2021-06-29 08:52:21 +02:00
parent c7c1f436f2
commit bca643e1fd
@@ -42,15 +42,15 @@ class VoiceMessageAttachmentCacheManager {
static let sharedManager = VoiceMessageAttachmentCacheManager()
// private let workQueue: DispatchQueue
private let workQueue: DispatchQueue
private var completionCallbacks = [String: [CompletionWrapper]]()
private var samples = [String: [Int: [Float]]]()
private var finalURLs = [String: URL]()
// private init() {
// workQueue = DispatchQueue(label: "io.element.VoiceMessageAttachmentCacheManager.queue", qos: .userInitiated)
// }
private init() {
workQueue = DispatchQueue(label: "io.element.VoiceMessageAttachmentCacheManager.queue", qos: .userInitiated)
}
func loadAttachment(_ attachment: MXKAttachment, numberOfSamples: Int, completion: @escaping (Result<(URL, [Float]), Error>) -> Void) {
guard attachment.type == MXKAttachmentTypeVoiceMessage else {
@@ -73,9 +73,9 @@ class VoiceMessageAttachmentCacheManager {
return
}
// workQueue.async {
workQueue.async {
self.enqueueLoadAttachment(attachment, identifier: identifier, numberOfSamples: numberOfSamples, completion: completion)
// }
}
}
private func enqueueLoadAttachment(_ attachment: MXKAttachment, identifier: String, numberOfSamples: Int, completion: @escaping (Result<(URL, [Float]), Error>) -> Void) {
@@ -92,7 +92,6 @@ class VoiceMessageAttachmentCacheManager {
analyser?.samples(count: numberOfSamples, completionHandler: { samples in
// Dispatch back from the WaveformAnalyzer's internal queue
DispatchQueue.main.async {
// self.workQueue.async {
guard let samples = samples else {
self.invokeFailureCallbacksForIdentifier(identifier, error: VoiceMessageAttachmentCacheManagerError.samplingError)
return