I have 3d party library (Firestore) that has this method
func listenToEvents(handler: ([Result], Error) -> Void)
handler in this method is called many times (after any updates of the data). I want to convert it to Publisher
Here is my code now:
var resultsPublisher: AnyPublisher<[Result], Error> {
Deferred {
Future { promise in
libraryObject.listenToEvents { results, error in // called multiple times
guard let results = results else {
promise(.failure(error))
return
}
// this can't be called several times,
// because Future's promise is supposed to be called only once
promise(.success(results))
}
}
}
.eraseToAnyPublisher()
}
So my Publisher produces value only once, because Future works this way. Are there any other Publishers (or may be a different approach) to accomplish that?