I am using Moya version: 11.0.2.
I want to call multiple APIs which are independent of each other. Can I do that with Moya? Is Moya providing this type of facility like i can call multiple API and it will notify me once all the API response is received.
The APIs are independent of each so the order of the API don't matter for me.
I want similar functionality like Promiss.all... then in the Javascript. Where I add multiple promises and in single then I get final callback once all APIs are completed.
I'm not sure that Moya provides such a functionality. But you still can use Moya together with PromiseKit to achieve the behaviour described above.
@slavasemeniuk Yes. I was thinking for the same. Do you have any reference of wrapper which shows Moya with PromiseKit.
func request(_ target: Target) -> Promise<Response> {
return Promise<Response> { seal in
self.request(target, callbackQueue: .main, progress: nil, completion: { result in
switch result {
case let .success(response):
seal.fulfill(response)
case let .failure(error):
seal.reject(error)
}
})
}
}
And now you can use it:
when(fulfilled: userProvider.request(.get), postsProvider.request(.get))
Okay. Thanks for the update. It worked with your code snippet.
Most helpful comment
And now you can use it: