Result could be extended with an async initialiser — something like this:
extension Result where Failure == Error {
init(awaiting task: () async throws -> Success) async {
do {
self = .success(try await task())
} catch {
self = .failure(error)
}
}
}
self.taskHandle = async {
self.result = await Result {
try await search(searchText: value)
}
}