Skip to content

Commit

Permalink
Update CodeExt.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ authored Jan 17, 2024
1 parent d6835b9 commit d901c00
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions DarockBili Watch App/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,33 @@ public func hideDigitalTime(_ b: Bool) {
public func autoRetryRequestApi(_ url: String, headers: HTTPHeaders?, maxReqCount: Int = 10, callback: @escaping (JSON, Bool) -> Void) {
DispatchQueue.global().async {
var reqResults = [JSON]()
var forTotal = 0
for i in 1...maxReqCount {
DarockKit.Network.shared.requestJSON(url, headers: headers) { respJson, _ in
reqResults.append(respJson)
forTotal++
}
}
while forTotal < maxReqCount { }
var isCalledback = false
var anyValidJson: JSON?
for result in reqResults {
if result != JSON() {
if CheckBApiError(from: result) {
callback(result, true)
isCalledback = true
break
} else {
anyValidJson = result
if i == maxReqCount {
var isCalledback = false
var anyValidJson: JSON?
for result in reqResults {
if result != JSON() {
if CheckBApiError(from: result) {
callback(result, true)
isCalledback = true
break
} else {
anyValidJson = result
}
}
}
if !isCalledback {
if let vj = anyValidJson {
callback(vj, true)
} else {
callback(JSON(), false)
}
}
}
}
}
if !isCalledback {
if let vj = anyValidJson {
callback(vj, true)
} else {
callback(JSON(), false)
}
}
}
}

Expand Down

0 comments on commit d901c00

Please sign in to comment.