Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active March 20, 2023 06:10
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/bec7b85098e57659c448b69519e8fde7 to your computer and use it in GitHub Desktop.
Save laevandus/bec7b85098e57659c448b69519e8fde7 to your computer and use it in GitHub Desktop.
final class DataFetcher {
func fetchData(for identifiers: [String]) async throws -> [String: Data] {
// …
}
}
extension DataFetcher {
func fetchData(for identifiers: [String], completionHandler: @escaping (Result<[String: Data], Error>) -> Void) {
Task {
do {
let data = try await fetchData(for: identifiers)
await MainActor.run {
completionHandler(.success(data))
}
}
catch {
await MainActor.run {
completionHandler(.failure(error))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment