美文网首页
Swift DispatchSemaphore信号量

Swift DispatchSemaphore信号量

作者: 大也 | 来源:发表于2021-08-12 09:59 被阅读0次
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

相关文章

网友评论

      本文标题:Swift DispatchSemaphore信号量

      本文链接:https://www.haomeiwen.com/subject/hmpwmltx.html