/ImageProcessor.swift Secret
Last active
March 5, 2023 01:36
Star
You must be signed in to star a gist
This file contains 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
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