AsyncRequest
处理异步代码的有用类
Request
是一个对象,其中包含可以在未来某个点异步调用的闭包
let request = Request<String>(successHandler: { string in
print(string)
})
根据某些计算的结果,请求可能是成功的
request.complete(with: "Success!")
或者不成功
request.complete(with: TestError.error)
无论如何,请求会结束
request.finished {
print("did finish")
}
请求可以被取消
request.cancel()
可以添加闭包
request.success(handler: { string in
print("Result: \(string)")
})
request.fail { error in
print("Error: \(error)")
}
request.finished {
print("request did complete")
})