Skip to content

Instantly share code, notes, and snippets.

Last active March 5, 2023 01:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
struct ImageProcessor {
static func process(identifier: Int) async throws -> Data {
// Read image data
try await Task.sleep(nanoseconds: UInt64(identifier) * UInt64(1e8))
try Task.checkCancellation()
// Simulate processing the data and transforming it
try await Task.sleep(nanoseconds: UInt64(1e8))
try Task.checkCancellation()
if identifier != 2 {
print("Success: \(identifier)")
return Data()
else {
print("Failing: \(identifier)")
throw ProcessingError.invalidData
enum ProcessingError: Error {
case invalidData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment