首先在PromiseKit 6中的语法

问题描述 投票:0回答:1

我想从PromiseKit中使用这个方法,但不知道如何编写正确的语法: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

ios swift promisekit
1个回答
0
投票

PromiseKit“首次”使用的基本示例:

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)
}
© www.soinside.com 2019 - 2024. All rights reserved.