You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! Could you provide any idea of how to decide which promises should I use according to local data?
For example: I have to register user this is promise No.1, also I have promise No.2 for sending his Push notifications token to server. The problem is how to call fulfilling promises No.1 & No.2 if I have enough data for promise No.2 and how to call just No.1 when I haven't data for promise No.2?
Should I use nested closures such as:
I'll try to describe:
I have number of API calls which are already return Promise and I try to understand which is the right way to use promises in situation when: I receive some data from first API call and then I should decide to call next promise or not according to previous response
Some code here:
func registerUser(with activeWindow: UIWindow?) {
let userService = UserService()
if let receipt = AppstoreService.receiptData {
let request = ReceiptRequest(
receipt: receipt.base64EncodedString(options: .lineLength64Characters))
when(fulfilled: userService.register(RegisterRequest.current), userService.validateReceipt(request))
.done { [weak self] (response, _) in
guard let self = self else { return }
SettingsManager.shared.serverToken = response.token
NotificationsManager.shared.sendUserId()
self.openApp()
}.catch { [weak self] error in
guard let self = self else {
return
}
self.showError(error, on: activeWindow)
}
} else {
userService.register(RegisterRequest.current)
.done { [weak self] response in
guard let self = self else { return }
SettingsManager.shared.serverToken = response.token
NotificationsManager.shared.sendUserId()
self.openApp()
}.catch { [weak self] error in
guard let self = self else {
return
}
self.showError(error, on: activeWindow)
}
}
}
Activity
mxcl commentedon Mar 5, 2020
Your question is not clear enough for me I’m afraid.
Sergozh commentedon Mar 5, 2020
I'll try to describe:
I have number of API calls which are already return Promise and I try to understand which is the right way to use promises in situation when: I receive some data from first API call and then I should decide to call next promise or not according to previous response
Some code here:
CristianCardosoA commentedon May 20, 2020
This is not a promise question, is an architecture question.
mxcl commentedon May 23, 2020
It is not clear to me still, one does not “call” a promise.
Try reading our documentation.