我想在PromiseKit中使用这个方法,但是不知道如何编写propper synthax:x
public func firstly<U: Thenable>(execute body: () throws -> U) -> Promise<U.T> {
do {
let rp = Promise<U.T>(.pending)
try body().pipe(to: rp.box.seal)
return rp
} catch {
return Promise(error: error)
}
}
firstly {
return someMethodWhichReturnsPromise()
}.then{
}
...
我该如何调用它? 代码来自:https://github.com/mxcl/PromiseKit/blob/master/Sources/firstly.swift
答案 0 :(得分:0)
PromiseKit的基本示例&#34;首先&#34;用法:
func someMethodWhichReturnsPromise() -> Promise<Int> {
// return promise
}
firstly {
someMethodWhichReturnsPromise()
}.then {
// Execute more logic here after 'firstly' block completes
}.catch {
// handle error if you need to
handle(error: $0)
}