data: busyWorkAsync should return the task

This commit is contained in:
osy 2024-02-23 21:05:12 -08:00
parent 52a1f454be
commit 0a8bff6552
1 changed files with 7 additions and 3 deletions

View File

@ -886,16 +886,20 @@ struct AlertMessage: Identifiable {
/// Execute a task with spinning progress indicator (Swift concurrency version)
/// - Parameter work: Function to execute
func busyWorkAsync(_ work: @escaping @Sendable () async throws -> Void) {
@discardableResult
func busyWorkAsync<T>(_ work: @escaping @Sendable () async throws -> T) -> Task<T, any Error> {
Task.detached(priority: .userInitiated) {
await self.setBusyIndicator(true)
do {
try await work()
let result = try await work()
await self.setBusyIndicator(false)
return result
} catch {
logger.error("\(error)")
await self.showErrorAlert(message: error.localizedDescription)
await self.setBusyIndicator(false)
throw error
}
await self.setBusyIndicator(false)
}
}