我有以下操作:
class CreateObjectOperation {
// ...
func promise() -> Promise<Object>
}
class DeleteObjectOperation {
// ...
func promise() -> Promise<Void>
}
我希望能够then/catch/finally
为两者使用相同的块。我尝试了以下方法:
let foo: Bool = ...
firstly {
(foo ?
CreateObjectOperation().promise() :
DeleteObjectOperation().promise()
) as Promise<AnyObject>
}.then { _ -> Void in
// ...
}.finally {
// ...
}.catch { error in
// ...
}
但这不会编译。是否有任何可行的解决方案(除了将代码从块移动到单独的函数,我想避免)?