let semaphore = DispatchSemaphore(value: 1) 初始化信号量为1
concurrentQueue.async() {
semaphore.wait()
self.chVM.requestChildList(.Subscription, {
print("3")
semaphore.signal()
})
}
let semaphore = DispatchSemaphore(value: 1) 初始化信号量为1
semaphore.wait() 信号量 -1
semaphore.signal() 信号量为+1
// 创建一个并发队列
let concurrentQueue = DispatchQueue(label: "concurrentQueue", attributes: .concurrent)
//初始化信号量为1
let semaphore = DispatchSemaphore(value: 1)
// 异步操作加入第一个网络请求
concurrentQueue.async() {
semaphore.wait()
self.boVM.requsetBoutique_list(1, {
sleep(3)
print("1-----------1")
semaphore.signal()
})
}
// 异步操作加入第二个网络请求
concurrentQueue.async() {
semaphore.wait()
self.boVM.requsetBoutique_list(1, {
print("2")
semaphore.signal()
})
}
// 异步操作加入第三个网络请求
concurrentQueue.async() {
semaphore.wait()
self.chVM.requestChildList(.Subscription, {
print("3")
semaphore.signal()
})
}
https://www.jianshu.com/p/bc1687a1f840
网友评论