google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confused when retry a Promise variable

EkkoG opened this issue · comments

commented

With the example in the doc, https://github.com/google/promises/blob/master/g3doc/index.md#retry

retry method wraps a method that always returns a new Promise, so when the Promise of the first time method failed, retry will call the fetch method again and create a new Promise, and all work perfectly.

But if retry a Promise variable, things get wired.

let p = Promise<Int> { resolve, reject in
    print("promise")
    reject(NSError(domain: "promise", code: 1, userInfo: nil))
}

retry {
    p
}.then { _ in
    print("then")
}.catch { _ in
    print("catch")
}

code wrapped by Promise p will only run once, not twice, does this is a bug or feature?