Skip to content

Commit

Permalink
#4090 - Use a dedicated dispatch queue for process
Browse files Browse the repository at this point in the history
  • Loading branch information
gileluard committed Jun 29, 2021
1 parent e0cbe49 commit e8a3084
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit e8a3084

Please sign in to comment.