Return a promise in `then` of a `all` promise
anhtukhtn opened this issue · 2 comments
anhtukhtn commented
Firstly, thank for the great repo.
I try to (way 1) // it works in JS
func fetchInfo() -> Promise<[String]> {
return all(fetch1(),
fetch2())
.then { [weak self] in
self?.doThing()
return($0) // got 'Unexpected non-void return value in function' here
}
}
I have to do (way 2)
func fetchInfo() -> Promise<[String]> {
return Promise<[String]> { [weak self] fulfill, _ in
all(fetch1(),
fetch2())
.then { [weak self] in
self?.doThing()
fulfill($0)
}
}
}
The question is can I archive it by the way 1?
Thank you very much
shoumikhin commented
Are you effectively trying to do something like this?
func fetchInfo() -> Promise<[String]> {
return all(fetch1(), fetch2()).then { [weak self] (fetch1Data, _) -> [String] in
self?.doThing()
return fetch1Data
}
}
anhtukhtn commented
Thank you very much. It works perfectly..