Search code examples
swiftasynchronouspromisepromisekit

PromiseKit how to return "when(resolved)" as a promise?


I have a series of functions that look like this:

func getA() -> Promise<Void> {
  // code
}

func getB() -> Promise<Void> {
  // code
}

func getC() -> Promise<Void> {
  // code
}

I want to return a Promise when all of these are finished. Here's what I tried:

func getStuff() -> Promise<[Result<Void>]> {
  return when(resolved: [getA(), getB(), getC()])
}

But I'm getting a compile error: 'Result' is ambiguous for type lookup in this context. How can I achieve this?


Solution

  • func getStuff() -> Promise<[PromiseKit.Result<Void>]> {
        return when(resolved: [getA(), getB(), getC()])
    }