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

Question about chaining with all() #19

Open
j796160836 opened this issue Apr 22, 2019 · 0 comments
Open

Question about chaining with all() #19

j796160836 opened this issue Apr 22, 2019 · 0 comments

Comments

@j796160836
Copy link

j796160836 commented Apr 22, 2019

Hi all,
I have using kovenant framework with some questions
I would like to fetch a table of contents and fetch the content of the table
simultaneously, then output a mixed list with table content title and content itself.

But I faced the problems for coding with kovenant.

For example, I have MySubject and MySubjectDetails class.

class MySubject {
    var id: String = ""
    var name: String = ""
}

class MySubjectDetails {
    var id: String = ""
    var name: String = ""
    var data: List<String> = ArrayList()
}

and APICalls class (part of code is pseudo code),

object APICalls {
    fun getSubjects(): Promise<List<MySubject>, Exception> {
        val deferred = deferred<List<MySubject>, Exception>()
        // ... API calls ...
        return deferred.promise
    }

    fun getSubjectById(id: String): Promise<MySubjectDetail, Exception> {
        val deferred = deferred<MySubjectDetail, Exception>()
        // ... API calls ...
        return deferred.promise
    }
}

I may fetch the data like is:

APICalls.getSubjects().then { subjects ->
    val promises = subjects.map {
        APICalls.getSubjectById(it.id)
    }
    all(promises)
}.then { promise: Promise<List<MySubjectDetail>, Exception> ->
    //       ^~~~~~ What's this?
}

I will get a result with Promise<List<MySubjectDetail>, Exception> type then I can't continue the code.
I expected it will be a combined list (List<MySubjectDetail>) but it comes up a Promise<List<MySubjectDetail>, Exception> object thats confused me.

How can I do or fix the code? Thanks.

@j796160836 j796160836 changed the title Chaining with all() Question about chaining with all() Apr 22, 2019
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

1 participant