ChainRequest
open class ChainRequest : HTTPRequestProtocol, RequestDelegate, @unchecked Sendable
队列请求类
-
队列请求完成句柄
Declaration
Swift
public typealias Completion = @MainActor @Sendable (ChainRequest) -> Void
-
回调处理句柄声明
Declaration
Swift
public typealias CallbackHandler = @Sendable (ChainRequest, HTTPRequest) -> Void
-
当前请求数组
Declaration
Swift
open private(set) var requestArray: [HTTPRequest] { get }
-
事件代理
Declaration
Swift
open weak var delegate: ChainRequestDelegate?
-
成功完成回调
Declaration
Swift
open var successCompletionBlock: Completion?
-
失败完成回调
Declaration
Swift
open var failureCompletionBlock: Completion?
-
自定义取消回调句柄,不一定主线程调用
Declaration
Swift
open var requestCancelledBlock: (@Sendable (ChainRequest) -> Void)?
-
请求标签,默认0
Declaration
Swift
open var tag: Int
-
自定义请求配件数组
Declaration
Swift
open var requestAccessories: [RequestAccessoryProtocol]?
-
最后一个导致队列请求成功的请求
Declaration
Swift
open private(set) var succeedRequest: HTTPRequest? { get }
-
最后一个导致队列请求失败的请求
Declaration
Swift
open private(set) var failedRequest: HTTPRequest? { get }
-
是否自动显示错误信息
Declaration
Swift
open var autoShowError: Bool { get set }
-
当前网络错误
Declaration
Swift
open var error: Error? { get }
-
请求是否已取消
Declaration
Swift
open private(set) var isCancelled: Bool { get }
-
请求间的时间间隔
Declaration
Swift
open var requestInterval: TimeInterval
-
某个请求失败时,是否立即停止队列请求,默认true
Declaration
Swift
open var stoppedOnFailure: Bool
-
某个请求成功时,是否立即停止队列请求,默认false
Declaration
Swift
open var stoppedOnSuccess: Bool
-
请求构建句柄,所有请求完成后才会主线程调用
Declaration
Swift
open var requestBuilder: (@Sendable (_ chainRequest: ChainRequest, _ previousRequest: HTTPRequest?) -> HTTPRequest?)?
-
Undocumented
Declaration
Swift
public init()
-
添加请求,可设置请求完成回调
Declaration
Swift
@discardableResult open func addRequest(_ request: HTTPRequest, callback: CallbackHandler? = nil) -> Self
-
开始请求,仅能调用一次
Declaration
Swift
@discardableResult open func start() -> Self
-
取消请求
Declaration
Swift
open func cancel()
-
开始请求并指定成功、失败句柄
Declaration
Swift
@discardableResult open func start(success: Completion?, failure: Completion?) -> Self
-
开始请求并指定完成句柄
Declaration
Swift
@discardableResult open func start(completion: Completion?) -> Self
-
请求取消句柄,不一定主线程调用
Declaration
Swift
@discardableResult open func requestCancelledBlock(_ block: (@Sendable (ChainRequest) -> Void)?) -> Self
-
自定义响应完成句柄
Declaration
Swift
@discardableResult open func response(_ completion: Completion?) -> Self
-
自定义响应成功句柄
Declaration
Swift
@discardableResult open func responseSuccess(_ block: Completion?) -> Self
-
自定义响应失败句柄
Declaration
Swift
@discardableResult open func responseFailure(_ block: Completion?) -> Self
-
快捷设置响应失败句柄
Declaration
Swift
@discardableResult open func responseError(_ block: (@MainActor @Sendable (Error) -> Void)?) -> Self
-
清理完成句柄
Declaration
Swift
open func clearCompletionBlock()
-
显示网络错误,默认显示Toast提示
Declaration
Swift
open func showError()
-
添加请求配件
Declaration
Swift
@discardableResult open func addAccessory(_ accessory: RequestAccessoryProtocol) -> Self
-
请求完成回调
Declaration
Swift
@MainActor open func requestFinished(_ request: HTTPRequest)
-
请求失败回调
Declaration
Swift
@MainActor open func requestFailed(_ request: HTTPRequest)
-
response()
Asynchronous异步获取完成响应,注意非Task取消也会触发(Continuation流程)
Declaration
Swift
public func response() async -> ChainRequest
-
responseSuccess()
Asynchronous异步获取成功响应,注意非Task取消也会触发(Continuation流程)
Declaration
Swift
public func responseSuccess() async throws -> ChainRequest