Synthax首先出现在PromiseKit 6中

时间:2018-03-01 11:36:10

标签: ios swift promisekit

我想在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

1 个答案:

答案 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)
}