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
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