Last active
November 9, 2021 23:01
-
-
Save wilg/c13c6b1fa14c0b3f55a7a1e734a988c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Task where Success == Void, Failure == Error { | |
@discardableResult | |
/// A task that performs a non-throwing `operation`. | |
static func strict<S>(priority: TaskPriority? = nil, operation: @escaping @Sendable () async -> S) -> Self { | |
Task(priority: priority, operation: { | |
_ = await operation() | |
}) | |
} | |
} | |
extension Task where Success == Void, Failure == Error { | |
@discardableResult | |
/// A task that performs `operation`, and alerts any errors thrown. | |
static func alertingError<S>(priority: TaskPriority? = nil, operation: @escaping @Sendable () async throws -> S) -> Self { | |
Task(priority: priority, operation: { | |
do { | |
_ = try await operation() | |
} catch { | |
alertError(error) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment