Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why won't Promise { } fire? #149

Open
mreaybeaton opened this issue Jun 24, 2020 · 3 comments
Open

Why won't Promise { } fire? #149

mreaybeaton opened this issue Jun 24, 2020 · 3 comments

Comments

@mreaybeaton
Copy link

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
Copy link
Collaborator

ykjchen commented Jun 25, 2020

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
Copy link
Author

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
Copy link
Contributor

nsoojin commented Jun 26, 2020

Try declaring the generic type

Promise<Void> {
  self.viewModel.services.signIn(username: username)
}...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants