Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active March 20, 2023 06:10
Embed
What would you like to do?
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