我正在尝试让我的循环等到定时队列完成后再循环agian。我该怎么办?
for retries in 0...3 {
do {
let triggerTime = DispatchTime.now() + .milliseconds(((2^(randomNumber*retries)*1000) + randomNumber))
DispatchQueue.main.asyncAfter(deadline: triggerTime, execute: {
//Don't loop until this is executed
self.socket.connect()
})
}
}
答案 0 :(得分:0)
您应该使套接字调用同步,但使整个连接过程(正在调用循环)异步。