Skip to content

Instantly share code, notes, and snippets.

@mikru1688
Last active April 4, 2017 08:53
Show Gist options
  • Save mikru1688/8e5a66e3ba3d8ece4e9bf62514628977 to your computer and use it in GitHub Desktop.
Save mikru1688/8e5a66e3ba3d8ece4e9bf62514628977 to your computer and use it in GitHub Desktop.
let group: DispatchGroup = DispatchGroup()
let queue1 = DispatchQueue(label: "queue1", attributes: .concurrent)
queue1.async(group: group) {
// 事件A
for i in 1 ... 100 {
print("i: \(i)")
}
}
let queue2 = DispatchQueue(label: "queue2", attributes: .concurrent)
queue2.async(group: group) {
// 事件B
for j in 101 ... 200 {
print("j: \(j)")
}
}
group.notify(queue: DispatchQueue.main) {
// 已處理完事件A和事件B
print("處理完成事件A和事件B...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment