Why won't Promise { } fire?
mreaybeaton opened this issue · 3 comments
mreaybeaton commented
If I have the following code
Promise {
statement1
}.then {
...
}.then {...}
statement1 doesn't fire, however if I have:
statement1.then{
...
}.then{...}
```
it does fire. Any ideas why that is?
ykjchen commented
Hey @mickeysox could you elaborate on what statement1
is? It looks like it could be a Promise, but I can't be sure just from the examples given. Thanks.
mreaybeaton commented
Hi @ykjchen
Here is my actual code:
@objc fileprivate func handleLogin() {
let hud = JGProgressHUD(style: .dark)
hud.textLabel.text = "Logging in"
hud.show(in: self.view)
if let username = phoneNumberTextField.text {
Promise {
self.viewModel.services.signIn(username: username)
}.then { _ in
self.viewModel.services.getUserAttributes()
}.then { user in
if let delegate = self.delegate {
delegate.update(user: user)
hud.dismiss(animated: true)
self.dismiss(animated: true)
}
}.catch { error in
let registerController = RegisterController(viewModel: self.viewModel)
registerController.username = username
registerController.delegate = self.delegate
hud.dismiss(animated: true)
self.navigationController?.pushViewController(registerController, animated: true)
}
}
}
The definition of signIn is
func signIn(username: String) -> Promise<AuthSignInResult>
The signIn method doesn't fire, but the "then" does. Changing this to
if let username = phoneNumberTextField.text {
self.viewModel.services.signIn(username: username)
.then { _ in
...
does fire.
Thanks.
nsoojin commented
Try declaring the generic type
Promise<Void> {
self.viewModel.services.signIn(username: username)
}...