Because ServiceStack use PromiseKit for it’s async calls on Swift, i made this little extension that convert a PromiseKit request into a Combine publisher.
extension Promise {
var publisher : AnyPublisher<T, Error> {
Future<T, Error> {
promise in
self.done {
body in
promise(.success(body))
}.catch {
error in
promise(.failure(error))
}
}.eraseToAnyPublisher()
}
}
Let’s say you have a ServiceStack Client witch return a Promise you can do something like the following.
let rq = GetListings()
client.getAsync(rq)
.publisher
.map {
response in
response.listings
}
....