Skip to content

Commit

Permalink
Move download to main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin_wojnarowski committed Jan 28, 2022
1 parent 0b16f6c commit 76ee38a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions ios/Classes/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,24 @@ import Foundation

@objc
func handleContentKeyDelegateDidSavePersistableContentKey(notification: Notification) {
guard
let url = notification.userInfo?["url"] as? URL,
let pendingKeyData = pendingKeyDataMap.removeValue(forKey: url.absoluteString)
else {
print("error while retrieving pending download values")
return
}
// This handle can be called from different threads. NotificationCenter runs callbacks in the thread that posted the notification.
// Thus we move excecution to the main thread to avoid data races.

DispatchQueue.main.async {
guard
let url = notification.userInfo?["url"] as? URL,
let pendingKeyData = self.pendingKeyDataMap.removeValue(forKey: url.absoluteString)
else {
print("error while retrieving pending download values")
return
}

download(
pendingKeyData.asset,
dataString: pendingKeyData.dataString,
eventChannel: pendingKeyData.eventChannel,
result: pendingKeyData.flutterResult)
self.download(
pendingKeyData.asset,
dataString: pendingKeyData.dataString,
eventChannel: pendingKeyData.eventChannel,
result: pendingKeyData.flutterResult)
}
}
}

Expand Down

0 comments on commit 76ee38a

Please sign in to comment.