//设置请求超时时间
let requestTimeoutClosure = { (endpoint: Endpoint, done: @escaping MoyaProvider<AppService>.RequestResultClosure) in
do {
var request = try endpoint.urlRequest()
request.timeoutInterval = 10
done(.success(request))
} catch {
return
}
}
对比:
//普通的
let appProvider = MoyaProvider<AppService>()
//设置了超时时间的
let requestTimeoutProvider = MoyaProvider<AppService>(requestClosure: requestTimeoutClosure)
网友评论