7ball
7ball

Reputation: 2315

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?

Upvotes: 0

Views: 1804

Answers (2)

mxcl
mxcl

Reputation: 26893

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

Upvotes: 1

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276446

There are several things named Result in your code and you need to tell Swift that Result in this case refers to PromiseKit.Result or to use Resolution assuming it's not taken in the namespace and you don't care about the related ErrorConsumptionToken.

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

Upvotes: 0

Related Questions