Question about chaining with `all()`
j796160836 opened this issue · comments
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.