我的承诺用法如下 -
echo '"JANE","BOB","TIM","HARRY"' | tr -s ',' '\n' | sort | tr -s '\n' ',' | sed s/,$//g
我试图弄清楚如何利用when(fulfilled: [promise]).then {(response) -> Void in
}.catch { (error) in
print(error)
}
的{{1}}属性,但到目前为止还没有运气。提前致谢。
答案 0 :(得分:0)
PromiseKit本身有一个例子:
https://github.com/mxcl/PromiseKit/blob/master/Tests/CorePromise/03_WhenTests.swift#L120-L141
func testProgress() {
let ex = expectation(description: "")
XCTAssertNil(Progress.current())
let p1 = after(.milliseconds(10))
let p2 = after(.milliseconds(20))
let p3 = after(.milliseconds(30))
let p4 = after(.milliseconds(40))
let progress = Progress(totalUnitCount: 1)
progress.becomeCurrent(withPendingUnitCount: 1)
when(fulfilled: p1, p2, p3, p4).done { _ in
XCTAssertEqual(progress.completedUnitCount, 1)
ex.fulfill()
}
progress.resignCurrent()
waitForExpectations(timeout: 1, handler: nil)
}