google / promises

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

Confused when retry a Promise variable #194

Open EkkoG opened 1 year ago

EkkoG commented 1 year ago

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?