mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-27 13:54:01 +02:00
Fix async call not waiting for results
This commit is contained in:
@@ -32,7 +32,7 @@ class PlayerProgress {
|
|||||||
|
|
||||||
public func syncToServer() async {
|
public func syncToServer() async {
|
||||||
let backgroundToken = await UIApplication.shared.beginBackgroundTask(withName: "ABS:syncToServer")
|
let backgroundToken = await UIApplication.shared.beginBackgroundTask(withName: "ABS:syncToServer")
|
||||||
updateAllServerSessionFromLocalSession()
|
await updateAllServerSessionFromLocalSession()
|
||||||
await UIApplication.shared.endBackgroundTask(backgroundToken)
|
await UIApplication.shared.endBackgroundTask(backgroundToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,11 +87,15 @@ class PlayerProgress {
|
|||||||
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.localProgress.rawValue), object: nil)
|
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.localProgress.rawValue), object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateAllServerSessionFromLocalSession() {
|
private func updateAllServerSessionFromLocalSession() async {
|
||||||
let sessions = try! Realm().objects(PlaybackSession.self).where({ $0.serverConnectionConfigId == Store.serverConfig?.id })
|
await withTaskGroup(of: Void.self) { [self] group in
|
||||||
for session in sessions {
|
for session in try! await Realm().objects(PlaybackSession.self).where({ $0.serverConnectionConfigId == Store.serverConfig?.id }) {
|
||||||
let session = session.freeze()
|
let session = session.freeze()
|
||||||
Task { await updateServerSessionFromLocalSession(session) }
|
group.addTask {
|
||||||
|
await self.updateServerSessionFromLocalSession(session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await group.waitForAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user