Created
November 15, 2018 19:33
-
-
Save vialyx/260fc99ce281651d7f9c5c193823e336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let group = DispatchGroup() | |
let workItemFirst = DispatchWorkItem { | |
print("exec 1st WI") | |
// 1 | |
group.leave() | |
} | |
let workItemSecond = DispatchWorkItem { | |
print("exec 2nd WI") | |
// 2 | |
group.leave() | |
} | |
let queue = DispatchQueue(label: "queue") | |
queue.async(execute: workItemFirst) | |
group.enter() | |
queue.async(execute: workItemSecond) | |
group.enter() | |
group.notify(queue: .main) { | |
print("exec group notify in main queue") | |
// 4 | |
} | |
print("main exec") | |
// 2 | |
/* console output | |
exec 1st WI | |
main exec | |
exec 2nd WI | |
exec group notify in main queue | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment