Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active March 5, 2023 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/e70fd789cb83f6e40b6bd8801bda3aab to your computer and use it in GitHub Desktop.
Save laevandus/e70fd789cb83f6e40b6bd8801bda3aab to your computer and use it in GitHub Desktop.
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