Skip to content

Commit 7890640

Browse files
committed
chore: some initial changes to async handling
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 5cecd43 commit 7890640

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Sushitrain/PhotoBackupView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,17 @@ struct PhotoBackupSettingsView: View {
341341
authorizationStatus = PHPhotoLibrary.authorizationStatus()
342342
self.folders = await appState.folders().filter({ $0.isSuitablePhotoBackupDestination }).sorted()
343343
if self.authorizationStatus == .authorized {
344-
self.loadAlbums()
344+
await self.loadAlbums()
345345
}
346346
else {
347347
self.albums = []
348348
self.smartAlbums = []
349349
}
350350
}
351351

352-
private func loadAlbums() {
352+
@concurrent private func loadAlbums() async {
353+
dispatchPrecondition(condition: .notOnQueue(.main))
354+
353355
var albums: [PHAssetCollection] = []
354356
let options = PHFetchOptions()
355357
options.sortDescriptors = [NSSortDescriptor(key: "localizedTitle", ascending: true)]
@@ -358,7 +360,10 @@ struct PhotoBackupSettingsView: View {
358360
userAlbums.enumerateObjects { (collection, _, _) in
359361
albums.append(collection)
360362
}
361-
self.albums = albums
363+
364+
DispatchQueue.main.async {
365+
self.albums = albums
366+
}
362367

363368
// Fetch system albums, including 'Recents'
364369
var smartAlbums: [PHAssetCollection] = []
@@ -368,7 +373,10 @@ struct PhotoBackupSettingsView: View {
368373
systemAlbums.enumerateObjects { (collection, _, _) in
369374
smartAlbums.append(collection)
370375
}
371-
self.smartAlbums = smartAlbums
376+
377+
DispatchQueue.main.async {
378+
self.smartAlbums = smartAlbums
379+
}
372380
}
373381

374382
#if os(iOS)

Sushitrain/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ func writeTextToPasteboard(_ text: String) {
10001000

10011001
// Run a possibly blocking task in the background (for calls into Go code)
10021002
func goTask(_ block: @Sendable @escaping () async throws -> Void) async throws {
1003-
try await Task.detached {
1003+
try await Task { @concurrent in
10041004
dispatchPrecondition(condition: .notOnQueue(.main))
10051005
try await block()
10061006
}.value

0 commit comments

Comments
 (0)