Skip to content

Commit

Permalink
data: busyWorkAsync should return the task
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Feb 25, 2024
1 parent 52a1f45 commit 0a8bff6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 0a8bff6

Please sign in to comment.