保存承诺履行并拒绝承诺

时间:2021-12-03 19:43:46

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)'

我得到错误无法使用类型'([String:(NSError) - > Void],forKey:String)'的参数列表调用'updateValue'

1 个解决方案

#1


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.)

完成和拒绝变量具有不同的类型,因此它们不能作为单独的值包含在同一个字典或数组中。 (除非你创建一个包含Any的字典/数组,否则会丢失所需的类型信息。)

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

查看Promise.pendingPromise()。您可以拥有一系列PendingPromises。

#1


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.)

完成和拒绝变量具有不同的类型,因此它们不能作为单独的值包含在同一个字典或数组中。 (除非你创建一个包含Any的字典/数组,否则会丢失所需的类型信息。)

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

查看Promise.pendingPromise()。您可以拥有一系列PendingPromises。