等待循环,直到队列完成后再继续

时间:2018-07-09 18:38:17

标签: ios swift multithreading loops wait

我正在尝试让我的循环等到定时队列完成后再循环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()
        })
    }
}

1 个答案:

答案 0 :(得分:0)

您应该使套接字调用同步,但使整个连接过程(正在调用循环)异步。