google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.8k stars 294 forks source link

how to make catch() to then()? #103

Closed davidfuzju closed 5 years ago

davidfuzju commented 5 years ago

hi there, I migrate from PromiseKit to promises recently, and I have a question that is there any way to return a Promise with resolved value to make promise chain go next then(). for example:

[self fetchRemoteData]
.then(^id (id rawData) {
 // do result transformed data
    return transformedData
})
.catch(^(NSError *error) {
// get transiformed result from local catch
    return cacheDataWhichHasBeenTransiformed
})
.then(^(id transformedData) {
// dosomething
})
ghost commented 5 years ago

Hi David, thank you for trying out Promises!

It sounds like recover is what you are looking for. It allows you to catch an error, address it, and continue the promise chain.

Please let us know if you have any additional questions.