Promisekit: Help me - Chaining recursive without knowing how many loops I'll have.

Created on 1 Feb 2017  Â·  2Comments  Â·  Source: mxcl/PromiseKit

I would like to make async query while last query returns nil. How to chain something like that? I can't create an array before, since I don't know how many chaining loops I will have.

Most helpful comment

func bar() -> Promise<T?> {
    //…
}

func baz() -> Promise<T> {
    return bar().then {
        if let done = value {
            return Promise(value: done)
        } else {
            return baz()
        }
    }
}

baz().then { value in
    // all done
}

All 2 comments

func bar() -> Promise<T?> {
    //…
}

func baz() -> Promise<T> {
    return bar().then {
        if let done = value {
            return Promise(value: done)
        } else {
            return baz()
        }
    }
}

baz().then { value in
    // all done
}

This just came in super hand for paged network.

Was this page helpful?
0 / 5 - 0 ratings