0

Hi I'm trying to create a promise and then save the function fulfill and reject into in array or dictionary . I don't know if this is possible to do I get some compiler erros. I know you can store functions inside array but I think since is inside the promise I need to do something else, here is my code

let requestPromise = Promise<Bool> { fulfill, reject in
    self.socket.emit(message,dic)
    let dicFunc = [ "fulfill": fulfill, "reject":reject]
    self.request.updateValue(dicFunc, forKey: uuid)
}

I get error Cannot invoke 'updateValue' with an argument list of type '([String : (NSError) -> Void], forKey: String)'

Cesar Oyarzun
  • 169
  • 2
  • 8

1 Answers1

0

The fulfill and reject variables have different types so they can't both be contained as separate values within the same dictionary or array. (Unless possibly if you make a dictionary/array that contains Any but that will loose needed type info.)

Check out Promise.pendingPromise(). You can hold an array of PendingPromises.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72