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

How to use? #750

Closed
hamada147 opened this issue Dec 11, 2017 · 4 comments
Closed

How to use? #750

hamada147 opened this issue Dec 11, 2017 · 4 comments

Comments

@hamada147
Copy link

hamada147 commented Dec 11, 2017

I just wanna know how to use it as it is extremely confusing to me.
I just want to use it in this kind of way

firslty {
    self.runMethod1()
}.then {
    self.runMethod2()
}.then {
    self.runMethod3()
}.then {
    self.runMethod4()
}.catch { error in
    // any errors in the whole chain land here
    print(error)
}

but I keep getting this error

Cannot convert value of type '()' to closure result type 'AnyPromise'
OR
Cannot convert value of type 'Void' to closure result type 'AnyPromise'

I tried doing it this way

firslty {
    self.runMethod1()
    return Promise<Void>()
}.then {
    self.runMethod2()
    return Promise<Void>()
}.then {
    self.runMethod3()
    return Promise<Void>()
}.then {
    self.runMethod4()
    return Promise<Void>()
}.catch { error in
    // any errors in the whole chain land here
    print(error)
}

but the last one always show this error

Cannot convert return expression of type 'Promise<Void>' to return type 'AnyPromise'

I don't need the method to return any value for the next method to run based on it. I just need them to run in that order. What am I doing wrong??

Please Note That:-
Every method is different API call.
And for each API request I'm using Moya

Edit #1:
here is my whole code

func getData(_ target: TTouchAPI_PreAuthenticationService) -> Promise<String> {
        self.RequestName = target.RequestName
        return Promise { fulfill, reject in
            self.Provider.request(target) { result in
                self.RequestCompleted = true
                switch result {
                case let .success(moyaResponse):
                    let statusCode = moyaResponse.statusCode
                    if (statusCode == 200) {
                        self.RequestSuccessed = true
                        self.data = moyaResponse.data
                        self.processData()
                        fulfill("Done")
                    }
                case let .failure(error):
                    reject(error)
                }
            }
            self.RequestSent = true
        }
    }

And I'm calling the same method 3 times in row with different request each time

        firstly {
            let Loc: PreAuthenticationWSService = PreAuthenticationWSService()
            Loc.getData(.getLocalization)
        }.then {
            let Theme: PreAuthenticationWSService = PreAuthenticationWSService()
            Theme.getData(.getThemes)
        }.then {
            let LoginInfo: PreAuthenticationWSService = PreAuthenticationWSService()
            LoginInfo.getData(.getLoginSetupInformation)
        }.catch { error in
            print(error)
        }

in each

then

I get the following error

Missing return in a closure expected to return 'Promise<()>'
@hamada147
Copy link
Author

I found your detailed documentations

@mxcl
Copy link
Owner

mxcl commented Dec 11, 2017

That is the old documentation,. please use: https://github.com/mxcl/PromiseKit/tree/master/Documentation

In addition we provide a Troubleshooting guide that exactly tells you how to deal with your error. This guide is linked from the README, always start at the README.

@doruchidean-lifeishard
Copy link

@mxcl The links are broken now

@mxcl
Copy link
Owner

mxcl commented Jul 15, 2021

The README provides these links, but I spent 4 seconds grabbing them for you from there.

Repository owner locked and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants